https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83256
Bug ID: 83256 Summary: inconsistent _Pragma behavior in multi-line macros Product: gcc Version: 8.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: preprocessor Assignee: unassigned at gcc dot gnu.org Reporter: arnd at linaro dot org Target Milestone: --- Created attachment 42777 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=42777&action=edit test case using _Pragma(GCC diagnostic push/pop) I tried using _Pragma("GCC diagnostic push") and _Pragma("GCC diagnostic pop") inside of a multi-line macro to turn a particular warning off inside code in that macro. This worked in some cases but not others. From what I can tell, the differences are: - If I first preprocess the file with "gcc -E", and then compile the preprocessed source, it works as expected. - In case of the "-Wattribute-alias" warning (added in gcc-8), I get the expected behavior only if I declare a structure before the _Pragma("GCC diagnostic pop"); removing the 'struct s;' line from the attached example leads to a warning for the incompatible alias. - With the -Wuninitialized warning, I could find no way to disabled it just inside of the macro expansion The same thing seems to happen with multi-line statements that I join with '\' line ends even without macros, but of course there is little use in that. I did not try what happens with other. Support for _Pragma("GCC diagnostic ...") was first added in gcc-4.2. This did not yet support push/pop, but the behavior of multi-line macros was already the same as with gcc-8: preprocessing the file makes it work as expected, but the integrated preprocessor seems to evaluate the _Pragma() early.