跳到正文

科技·工程

Bugs of GCC

Autre约 1 分钟
原文
文章信息与版本

文章信息

发布
2024年4月17日
收录
2025年12月12日
更新
2026年11月12日
篇幅
约 1 分钟

版本

  1. v1当前

原帖:https://zhaojinxi.blog.uoj.ac/blog/8996

C++
#include <cstdio>
struct Node {
    int x;
};
Node f(int A, int B) {
    if (A < 0) return {0};
    return {A / B + (A % B != 0)};
}
Node g(int C, int D) {
    if (C > 0) return {0};
    return {C / D + (C % D != 0)};
}
int main() {
    int n;
    scanf("%d", &n);
    f(1, 1);
    Node t = g(-1, n);
    printf("%d\n", t.x);
}

输入 0,正确输出应为 1

这份代码在开启 O2 优化后输出 0

相关 bug report:https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113907


原文