https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126003

--- Comment #2 from Douglas McIlroy <douglas.mcilroy at dartmouth dot edu> ---
This revision of the example still warns about only one of two overflows.
According to the syntax of the C23 standard, neither is parsed as a constant
expression. The  standard requires constant expressions to be evaluated at
compile time. In both cases here, however, compile-time evaluation is a
voluntary service of gcc. 

It is understandable that cases of the service vary with optimization level.
But it is strange that gcc is inconsistent about warning when the service
uncovers trouble.

#include <stdio.h>
#define TWOGIG 2000000000 // 2,000,000,000
int main() {
    printf("%d\n",TWOGIG+TWOGIG);  // evaluated under -O0
    int twogig = TWOGIG;
    printf("%d\n",twogig+twogig);  // evaluated under -O1
}

Reply via email to