https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95239
Bug ID: 95239 Summary: Unable to ignore -Wattribute-warning in macro Product: gcc Version: 10.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: e...@coeus-group.com Target Milestone: --- Created attachment 48573 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48573&action=edit Test case I'm trying to create a macro which evaluates an expression while ignoring warnings generated by the warning attribute. Basically, a slightly simplified version of what I want is: #define IGNORE_WARNING_ATTR(expr) (__extension__({ \ _Pragma("GCC diagnostic push") \ _Pragma("GCC diagnostic ignored \"-Wattribute-warning\"") \ int tmp = expr; \ _Pragma("GCC diagnostic pop") \ tmp; \ })) However, when I use it I still see the warning. If I don't use a macro, but instead just do int c = (__extension__({ _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wattribute-warning\"") int tmp = foo(argc); _Pragma("GCC diagnostic pop") tmp; })); It works as intended; no warning. If I use the macro version and preprocess the source file first, then compile the preprocessed file separately, it works. If I compile with g++ it works. Using the attached test case, I get: $ gcc -E -o warn-pp.c warn.c && gcc -o warn warn-pp.c $ g++ -o warn warn.c $ gcc -o warn warn.c warn.c: In function ‘main’: warn.c:23:31: warning: call to ‘foo’ declared with attribute warning: Calling foo [-Wattribute-warning] 23 | int b = IGNORE_WARNING_ATTR(foo(argc)); | ^~~~~~~~~ warn.c:4:15: note: in definition of macro ‘IGNORE_WARNING_ATTR’ 4 | int tmp = expr; \ | ^~~~