https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118813
Bug ID: 118813
Summary: Compile error when using __OPTIMIZE__ without value
Product: gcc
Version: 14.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: preprocessor
Assignee: unassigned at gcc dot gnu.org
Reporter: kistlin at protonmail dot ch
Target Milestone: ---
Hello, it's more a clarification I guess rather than a bug report.
Recently I compiled a project and got:
/usr/lib/gcc/x86_64-pc-linux-gnu/14.2.1/include/avx512bwintrin.h:202:17: error:
#if with no expression
202 | #if __OPTIMIZE__
| ^
The project only defined `#define __OPTIMIZE__`.
Based on the GCC manual one could argue the define is wrong.
But on the other hand the headers use different versions of #ifdef and #if.
https://github.com/gcc-mirror/gcc/blob/846837c2406ae7a52d9123b29c13e4b8b9d14224/gcc/config/i386/avx512bwintrin.h#L202
compared to this usage
https://github.com/gcc-mirror/gcc/blob/846837c2406ae7a52d9123b29c13e4b8b9d14224/gcc/config/i386/avx512bwintrin.h#L2841
gcc --version
gcc (GCC) 14.2.1 20250128
GCC manual Section 3.7.2 Common Predefined Macros
```
__OPTIMIZE__
__OPTIMIZE_SIZE__
__NO_INLINE__
These macros describe the compilation mode. __OPTIMIZE__ is defined in all
optimizing compilations. __OPTIMIZE_SIZE__ is defined if the compiler is
optimizing for size, not speed. __NO_INLINE__ is defined if no functions will
be inlined into their callers (when not optimizing, or when inlining has been
specifically disabled by -fno-inline).
These macros cause certain GNU header files to provide optimized definitions,
using macros or inline functions, of system library functions. You should not
use these macros in any way unless you make sure that programs will execute
with the same effect whether or not they are defined. If they are defined,
their value is 1.
```
For me as a non-regular reader of the manual `If they are defined, their value
is 1.` could have two meanings.
Either whoever defines the macro has to set its value to 1.
Or if #define __OPTIMIZE__ is used, the preprocessor sets its value to 1.
See also
https://gitlab.archlinux.org/archlinux/packaging/packages/gcc/-/issues/20#note_244143
for the same info and a minimal working example.
Could you shed some light on this? Thanks!