https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85266
Bug ID: 85266 Summary: Inconsistent _Pragma behavior for macro with and without arguments Product: gcc Version: 7.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: sdaniel.cole at gmail dot com Target Milestone: --- I'm trying to use the _Pragma operator to disable warnings for code inside a macro. It seems to work when the macro has no arguments (without parenthesis), but doesn't work when it has arguments (even having empty parenthesis causes the change in behavior). The following works as expected (shadow warning disabled for macro only): struct RAII{ RAII(); ~RAII(); }; #define RAII_BLOCK \ _Pragma("GCC diagnostic push \"-Wshadow\"") \ _Pragma("GCC diagnostic ignored \"-Wshadow\"") \ auto a = RAII(); \ _Pragma("GCC diagnostic pop") void foo() { RAII_BLOCK; { RAII_BLOCK; } } The following doesn't work as expected (a warning is still generated): struct RAII{ RAII(); ~RAII(); }; #define RAII_BLOCK() \ _Pragma("GCC diagnostic push \"-Wshadow\"") \ _Pragma("GCC diagnostic ignored \"-Wshadow\"") \ auto a = RAII(); \ _Pragma("GCC diagnostic pop") void foo() { RAII_BLOCK(); { RAII_BLOCK(); } } I compile the above using: g++ -c test.cpp -Wshadow https://godbolt.org/g/D22MYu