https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66711
Bug ID: 66711 Summary: GCC does not correctly restore diagnostic state after pragma GCC diagnostic pop with -Werror Product: gcc Version: 5.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: steffen.muething at iwr dot uni-heidelberg.de Target Milestone: --- Created attachment 35880 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=35880&action=edit MWE, compile with "gcc -Wextra -Werror wrong-diagnostic-pop.c" GCC 5.1.0 fails to correctly restore the diagnostics state after a "#pragma GCC diagnostic pop" if the program was compiled with -Werror: Instead of emitting an error, the compiler insteads issues a warning after the pragma. I've attached a simple example file. When compiled with "-Wextra -Werror", I'd expect the output: """ error.cc: In function 'int main()': error.cc:9:10: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare] x += x < y ? 1 : 0; ^ error.cc:18:10: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare] x += x < y ? 1 : 0; ^ cc1plus: all warnings being treated as errors """ But I get the following: """ error.cc: In function 'int main()': error.cc:9:10: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare] x += x < y ? 1 : 0; ^ error.cc:18:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] x += x < y ? 1 : 0; ^ cc1plus: all warnings being treated as errors """ The second diagnostic was turned into a warning. All older versions of GCC that I have available and that support diagnostic push/pop (4.6.4, 4.7.4, 4.8.4, 4.9.2) handle this correctly and issue an error in both cases. Example output from GCC 4.9.2: """ wrong-diagnostic-pop.c: In function 'main': wrong-diagnostic-pop.c:9:10: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare] x += x < y ? 1 : 0; ^ wrong-diagnostic-pop.c:18:10: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare] x += x < y ? 1 : 0; ^ cc1: all warnings being treated as errors """ The problem is also present in the C++ frontend.