[Bug c/105120] __OPTIMIZE__ macro incorrectly defined when using pragma(optimize) with push_options/pop_options

andrey.turkin at gmail dot com gcc-bugzilla@gcc.gnu.org
Fri Apr 1 07:33:11 GMT 2022


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

--- Comment #3 from Andrey Turkin <andrey.turkin at gmail dot com> ---
Personally I don't care much about implications of bug 48026; the issue that
affects me is pop_options leaking some state changed by pragmas inside
push_options/pop_options, namely macros. That sample was derived from a
real-world example there we use a third-party library (fmt) which does this
optimize thing in its core header - it defines a number of inline functions and
supposedly the optimize makes resulting debug binaries smaller (not sure how
optimize override works with regard to inline functions but they must've done
this for a reason); that library is included into our logging header which is
used pretty much everywhere, and it is PCHed. Which means that we are getting
inconsistent compiler state everywhere in a debug build, and there is no way to
separate it into its own TU.
I think pop_options should roll back these compiler-defined macros; in the
meantime there is a workaround - one can explicitely wrap such
push_options/pop_options block with push_macro("__OPTIMIZE__")/pop_macro pair.


More information about the Gcc-bugs mailing list