https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66099
Bug ID: 66099 Summary: _Pragma diagnostic 'ignored' in macro with strict-overflow not suppressing warning fully with -Werror Product: gcc Version: 5.1.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: dd0t at users dot sourceforge.net Target Milestone: --- Created attachment 35517 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=35517&action=edit Repro case with description When compiling the attached sample with g++ 5.1.0 or 5.1.1 and -Werror the suppression of strict-overflow works for the approaches taken in the testing2 and testing3 functions but the analogous one in the TESTING macro will still produce a strict-overflow warning. This warning will strangely - even though -Werror is set - not result in an error though. With g++ 4.9.2 the diagnostic ignored seems to have no effect at all and a warning with resulting error is created in the TESTING macro. When compiling with gcc instead of g++ - as intended - none of the approaches leads to a warning or an error in any of the aforementioned versions. A related bug might be https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53469 . I found it when trying to create the repro sample for this bug. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53431 has the same g++ only behavior but - with my limited understanding of g++ internals - I wouldn't expect the strict-overflow warning to be created in that early processing stage causing that issue. Repro sample: // g++ -fstrict-overflow -Wstrict-overflow -Werror macro.c // gcc -fstrict-overflow -Wstrict-overflow -Werror macro.c // Under g++: // The TESTING macro still presents a strict-overflow warning // with gcc 5.1.0 and 5.1.1 even though it should be ignored. // With gcc 4.9.2 the ignore is completely ignored and the // compilation fails due to the incorrectly generated warning. // Under gcc: // Works as expected in all versions. #define TESTING(_Exp) { \ _Pragma("GCC diagnostic push") \ _Pragma("GCC diagnostic ignored \"-Wstrict-overflow\"") \ int b = _Exp ; \ _Pragma("GCC diagnostic pop") \ } void testing() { int i = 4; TESTING(i + 4 < i); } void testing2() { #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wstrict-overflow" int j = 4; int b = j + 4 < j; #pragma GCC diagnostic pop } void testing3() { _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wstrict-overflow\"") int k = 4; int b = k + 4 < k; _Pragma("GCC diagnostic pop") } int main() { testing(); testing2(); testing3(); return 0; }