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

Mark Rohrbacher <m...@r-dev.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |m...@r-dev.de

--- Comment #4 from Mark Rohrbacher <m...@r-dev.de> ---
I tried to achieve something very similar to temporarily enable -Wswitch-enum
just for a single switch:

#define SWITCH_ENUM(x) \
    _Pragma("GCC diagnostic push") \
    _Pragma("GCC diagnostic warning \"-Wswitch-enum\"") \
    switch(x) \
    _Pragma("GCC diagnostic pop")

which doesn't work as expected in gcc7.4 and gcc8.4 (it works however in 9.1,
9.2 and trunk). Manually expanding the macro (as well as compiling the
preprocessor output) leads to the expected result.

It seems that the evaluation of _Pragma in macros happens after the 'real'
source code of the macro, so
#define _Pragma("X") my_code_here
seems to be interpreted as
#define my_code_here _Pragma("X")

When omitting _Pragma("GCC diagnostic pop") in the macro, -Wswitch-enum is
enabled within the switch body, but disabled for the switch itself.

Reply via email to