From PR35637 but this is a general issue of the diagnostic machinery. The problem is: -pedantic no warning, -pedantic-errors gives an error. Explanation: The pedantic warning is in a system header, so it doesn't get emitted. When using -pedantic-errors, it is an error, and errors are always emitted. Longer explanation: The problem is in diagnostics.c (diagnostic_report_diagnostic) which checks only for DK_WARNING if they should be inhibited (either because of -w or because location is within system headers. However, pedwarn() is passing a DK_ERROR when -pedantic-errors is enabled. One possible fix is that pedwarn() always passes a DK_WARNING type, while -pedantic-errors reclassifies -pedantic warnings to emit errors. In other words, -pedantic-errors would behave internally like -Werror=pedantic.
One testcase could use #include_next in a system header and compile with just -pedantic-errors. This should be silent but it currently emits an error. Another testcase could be just: static int sc = INT_MAX + 1; compiled with "-pedantic-errors -w". This should be silent as well, but it will give an error.
Thanks a lot Manuel! Maybe I will even be able to come to this, thanks to your suggestions for a fix.
(In reply to comment #2) > Thanks a lot Manuel! Maybe I will even be able to come to this, thanks to your > suggestions for a fix. > I think there is a problem with my suggestion: -pedantic-errors does not only affect -pedantic warnings but it also affects pedwarns that are not controlled by -pedantic. -Werror=pedantic would only affect those warnings controlled by -pedantic, so it would not be equivalent to -pedantic-errors. :( At the moment where diagnostic_report_diagnostic checks diagnostic_report_warnings_p (location), the machinery does not know that this is a pedwarn. I guess we could pass a special code DK_PEDWARN, and test for flag_pedantic_errors within diagnostic_report_diagnostic so we can reclassify it as DK_ERROR or DK_WARNING; or we could pass a special code DK_PEDERROR and for that code also check diagnostic_report_warnings_p before reclassifying it to DK_ERROR; or we could make a call to diagnostic_report_warnings_p (location) directly in pedwarn before passing down a DK_ERROR. Sorry I can't be more precise. This needs more time to think that I have available.
Subject: Bug 36901 Author: manu Date: Fri Aug 8 23:57:19 2008 New Revision: 138893 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=138893 Log: 2008-08-09 Manuel Lopez-Ibanez <manu@gcc.gnu.org> PR 36901 * diagnostic.def (DK_PEDWARN, DK_PERMERROR): New. * diagnostic.c (pedantic_warning_kind, permissive_error_kind): Moved from diagnostic.h (diagnostic_report_diagnostic): Return bool. Handle DK_PEDWARN and DK_PERMERROR. (emit_diagnostic): New. (warning0, pedwarn0): Delete. (warning, warning_at, pedwarn, permerror): Return bool. * diagnostic.h (pedantic_warning_kind, permissive_error_kind): Moved to diagnostic.c. (struct diagnostic_context): Use correct type for classify_diagnostic. (diagnostic_report_diagnostic): Update declaration. (emit_diagnostic): Declare. * errors.c (warning): Return bool. * errors.h (warning): Update declaration. * toplev.h (warning0, pedwarn0): Delete. (warning, warning_at, pedwarn, permerror): Return bool. * c-errors.c (pedwarn_c99, pedwarn_c90): Use DK_PEDWARN. * c-decl.c (locate_old_decl): Delete 'diag' argument. Always use inform. Update all calls. (diagnose_mismatched_decls): Check return value of warning/pedwarn before giving informative note. (implicit_decl_warning): Likewise. * c-typeck.c (build_function_call): Likewise. * tree-sssa.c (warn_uninit): Likewise. * builtins.c (gimplify_va_arg_expr): Likewise. fortran/ * f95-lang.c (gfc_mark_addressable): Use "pedwarn (0," instead of 'pedwarn0'. cp/ * cp-tree.h (struct diagnostic_context, struct diagnostic_info): Delete forward declarations. Check that toplev.h has not been included before this file. Include toplev.h and diagnostic.h. * error.c (cp_cpp_error): Use DK_PEDWARN. (cxx_incomplete_type_diagnostic): Update declaration. (cxx_incomplete_type_error): Use DK_ERROR. * typeck2.c (cxx_incomplete_type_diagnostic): Take a diagnostic_t as argument. Use emit_diagnostic. (cxx_incomplete_type_error): Use DK_ERROR. (add_exception_specifier): Use diagnostic_t instead of custom codes. * typeck.c (complete_type_or_else): Update call to cxx_incomplete_type_diagnostic. * init.c (build_delete): Likewise. * call.c (diagnostic_fn_t): Remove unused typedef. (build_temp): Pass a pointer to diagnostic_t. (convert_like_real): Use emit_diagnostic. (joust): Check return value of warning before giving informative note. * friend.c (do_friend): Check return value of warning before giving informative note. * parser.c (cp_parser_template_id): Likewise. testsuite/ * gcc.dg/pr36901-1.c: New. * gcc.dg/pr36901-3.c: New. * gcc.dg/pr36901-2.c: New. * gcc.dg/pr36901-4.c: New. * gcc.dg/pr36901-system.h: New. * gcc.dg/pr36901.h: New. * gcc.target/powerpc/altivec-macros.c: Update. * gcc.target/i386/regparm.c: Update. * gcc.dg/funcdef-var-1.c: Update. * gcc.dg/parm-mismatch-1.c: Update. * gcc.dg/attr-noinline.c: Update. * gcc.dg/wtr-static-1.c: Update. * gcc.dg/redecl-11.c: Update. * gcc.dg/pr27953.c: Update. * gcc.dg/proto-1.c: Update. * gcc.dg/decl-3.c: Update. * gcc.dg/redecl-13.c: Update. * gcc.dg/pr15360-1.c: Update. * gcc.dg/redecl-15.c: Update. * gcc.dg/enum-compat-1.c: Update. * gcc.dg/dll-3.c: Update. * gcc.dg/array-5.c: Update. * gcc.dg/Wredundant-decls-2.c: Update. * gcc.dg/inline4.c: Update. * gcc.dg/redecl-2.c: Update. * gcc.dg/inline-14.c: Update. * gcc.dg/tls/diag-3.c: Update. * gcc.dg/funcdef-var-2.c: Update. * gcc.dg/20041213-1.c: Update. * gcc.dg/old-style-then-proto-1.c: Update. * gcc.dg/decl-2.c: Update. * gcc.dg/redecl-12.c: Update. * gcc.dg/decl-4.c: Update. * gcc.dg/Wshadow-1.c: Update. * gcc.dg/transparent-union-2.c: Update. * gcc.dg/visibility-7.c: Update. * gcc.dg/dll-2.c: Update. * gcc.dg/redecl-16.c: Update. * gcc.dg/inline1.c: Update. * gcc.dg/decl-8.c: Update. * gcc.dg/nested-redef-1.c: Update. * gcc.dg/inline3.c: Update. * gcc.dg/redecl-1.c: Update. * gcc.dg/inline5.c: Update. * gcc.dg/pr35899.c: Update. * gcc.dg/noncompile/label-lineno-1.c: Update. * gcc.dg/noncompile/label-1.c: Update. * gcc.dg/noncompile/20020220-1.c: Update. * gcc.dg/noncompile/redecl-1.c: Update. * gcc.dg/redecl-5.c: Update. * gcc.dg/qual-return-3.c: Update. * gcc.dg/label-decl-4.c: Update. Added: trunk/gcc/testsuite/gcc.dg/pr36901-1.c trunk/gcc/testsuite/gcc.dg/pr36901-2.c trunk/gcc/testsuite/gcc.dg/pr36901-3.c trunk/gcc/testsuite/gcc.dg/pr36901-4.c trunk/gcc/testsuite/gcc.dg/pr36901-system.h trunk/gcc/testsuite/gcc.dg/pr36901.h Modified: trunk/gcc/ChangeLog trunk/gcc/builtins.c trunk/gcc/c-decl.c trunk/gcc/c-errors.c trunk/gcc/c-typeck.c trunk/gcc/cp/ChangeLog trunk/gcc/cp/call.c trunk/gcc/cp/cp-tree.h trunk/gcc/cp/error.c trunk/gcc/cp/friend.c trunk/gcc/cp/init.c trunk/gcc/cp/parser.c trunk/gcc/cp/typeck.c trunk/gcc/cp/typeck2.c trunk/gcc/diagnostic.c trunk/gcc/diagnostic.def trunk/gcc/diagnostic.h trunk/gcc/errors.c trunk/gcc/errors.h trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/f95-lang.c trunk/gcc/testsuite/ChangeLog trunk/gcc/testsuite/gcc.dg/20041213-1.c trunk/gcc/testsuite/gcc.dg/Wredundant-decls-2.c trunk/gcc/testsuite/gcc.dg/Wshadow-1.c trunk/gcc/testsuite/gcc.dg/array-5.c trunk/gcc/testsuite/gcc.dg/attr-noinline.c trunk/gcc/testsuite/gcc.dg/decl-2.c trunk/gcc/testsuite/gcc.dg/decl-3.c trunk/gcc/testsuite/gcc.dg/decl-4.c trunk/gcc/testsuite/gcc.dg/decl-8.c trunk/gcc/testsuite/gcc.dg/dll-2.c trunk/gcc/testsuite/gcc.dg/dll-3.c trunk/gcc/testsuite/gcc.dg/enum-compat-1.c trunk/gcc/testsuite/gcc.dg/funcdef-var-1.c trunk/gcc/testsuite/gcc.dg/funcdef-var-2.c trunk/gcc/testsuite/gcc.dg/inline-14.c trunk/gcc/testsuite/gcc.dg/inline1.c trunk/gcc/testsuite/gcc.dg/inline3.c trunk/gcc/testsuite/gcc.dg/inline4.c trunk/gcc/testsuite/gcc.dg/inline5.c trunk/gcc/testsuite/gcc.dg/label-decl-4.c trunk/gcc/testsuite/gcc.dg/nested-redef-1.c trunk/gcc/testsuite/gcc.dg/noncompile/20020220-1.c trunk/gcc/testsuite/gcc.dg/noncompile/label-1.c trunk/gcc/testsuite/gcc.dg/noncompile/label-lineno-1.c trunk/gcc/testsuite/gcc.dg/noncompile/redecl-1.c trunk/gcc/testsuite/gcc.dg/old-style-then-proto-1.c trunk/gcc/testsuite/gcc.dg/parm-mismatch-1.c trunk/gcc/testsuite/gcc.dg/pr15360-1.c trunk/gcc/testsuite/gcc.dg/pr27953.c trunk/gcc/testsuite/gcc.dg/pr35899.c trunk/gcc/testsuite/gcc.dg/proto-1.c trunk/gcc/testsuite/gcc.dg/qual-return-3.c trunk/gcc/testsuite/gcc.dg/redecl-1.c trunk/gcc/testsuite/gcc.dg/redecl-11.c trunk/gcc/testsuite/gcc.dg/redecl-12.c trunk/gcc/testsuite/gcc.dg/redecl-13.c trunk/gcc/testsuite/gcc.dg/redecl-15.c trunk/gcc/testsuite/gcc.dg/redecl-16.c trunk/gcc/testsuite/gcc.dg/redecl-2.c trunk/gcc/testsuite/gcc.dg/redecl-5.c trunk/gcc/testsuite/gcc.dg/tls/diag-3.c trunk/gcc/testsuite/gcc.dg/transparent-union-2.c trunk/gcc/testsuite/gcc.dg/visibility-7.c trunk/gcc/testsuite/gcc.dg/wtr-static-1.c trunk/gcc/testsuite/gcc.target/i386/regparm.c trunk/gcc/testsuite/gcc.target/powerpc/altivec-macros.c trunk/gcc/toplev.h trunk/gcc/tree-ssa.c
Fixed in GCC 4.4
Your fix causes a regression on the AVR: FAIL: gcc.dg/pr36901-4.c #include_next (test for errors, line ) Success with trunk revision 138883 Failed with trunk revision 138904
*** Bug 37069 has been marked as a duplicate of this bug. ***
I don't have AVR so I cannot know what exactly is going on or test a fix. However, I guess that the limits.h used by AVR do not use #include_next. So you could try by adding #include_next in pr36901-system.h, that is: - #include "pr36901.h" + #include_next "pr36901.h" Could you test that?
You're right in that limits.h for the AVR does not use #include_next. The limits.h that the AVR toolchain uses is installed by gcc. Unfortunately your suggestion makes the situation worse. There are now 4 failures instead of one: FAIL: gcc.dg/pr36901-1.c (test for excess errors) FAIL: gcc.dg/pr36901-4.c overflow (test for warnings, line ) FAIL: gcc.dg/pr36901-4.c overflow (test for errors, line ) FAIL: gcc.dg/pr36901-4.c (test for excess errors) Here are the details from the log: Executing on host: /usr/local/avrdev/gcc/build/gcc/xgcc -B/usr/local/avrdev/gcc/build/gcc/ /usr/local/avrdev/gcc/gcc/gcc/testsuite/gcc.dg/pr36901-1.c -pedantic-errors -DSTACK_SIZE=2048 -DNO_TRAMPOLINES -fno-show-column -S -DSIGNAL_SUPPRESS -mmcu=atmega128 -o pr36901-1.s (timeout = 300) In file included from /usr/local/avrdev/gcc/gcc/gcc/testsuite/gcc.dg/pr36901-1.c:3: /usr/local/avrdev/gcc/gcc/gcc/testsuite/gcc.dg/pr36901-system.h:2: error: pr36901.h: No such file or directory /usr/local/avrdev/gcc/gcc/gcc/testsuite/gcc.dg/pr36901-1.c: In function 'foo': /usr/local/avrdev/gcc/gcc/gcc/testsuite/gcc.dg/pr36901-1.c:6: error: 'sc' undeclared (first use in this function) /usr/local/avrdev/gcc/gcc/gcc/testsuite/gcc.dg/pr36901-1.c:6: error: (Each undeclared identifier is reported only once /usr/local/avrdev/gcc/gcc/gcc/testsuite/gcc.dg/pr36901-1.c:6: error: for each function it appears in.) compiler exited with status 1 output is: In file included from /usr/local/avrdev/gcc/gcc/gcc/testsuite/gcc.dg/pr36901-1.c:3: /usr/local/avrdev/gcc/gcc/gcc/testsuite/gcc.dg/pr36901-system.h:2: error: pr36901.h: No such file or directory /usr/local/avrdev/gcc/gcc/gcc/testsuite/gcc.dg/pr36901-1.c: In function 'foo': /usr/local/avrdev/gcc/gcc/gcc/testsuite/gcc.dg/pr36901-1.c:6: error: 'sc' undeclared (first use in this function) /usr/local/avrdev/gcc/gcc/gcc/testsuite/gcc.dg/pr36901-1.c:6: error: (Each undeclared identifier is reported only once /usr/local/avrdev/gcc/gcc/gcc/testsuite/gcc.dg/pr36901-1.c:6: error: for each function it appears in.) FAIL: gcc.dg/pr36901-1.c (test for excess errors) Excess errors: In file included from /usr/local/avrdev/gcc/gcc/gcc/testsuite/gcc.dg/pr36901-1.c:3: /usr/local/avrdev/gcc/gcc/gcc/testsuite/gcc.dg/pr36901-system.h:2: error: pr36901.h: No such file or directory /usr/local/avrdev/gcc/gcc/gcc/testsuite/gcc.dg/pr36901-1.c:6: error: 'sc' undeclared (first use in this function) /usr/local/avrdev/gcc/gcc/gcc/testsuite/gcc.dg/pr36901-1.c:6: error: (Each undeclared identifier is reported only once /usr/local/avrdev/gcc/gcc/gcc/testsuite/gcc.dg/pr36901-1.c:6: error: for each function it appears in.) Executing on host: /usr/local/avrdev/gcc/build/gcc/xgcc -B/usr/local/avrdev/gcc/build/gcc/ /usr/local/avrdev/gcc/gcc/gcc/testsuite/gcc.dg/pr36901-2.c -pedantic-errors -w -DSTACK_SIZE=2048 -DNO_TRAMPOLINES -fno-show-column -S -DSIGNAL_SUPPRESS -mmcu=atmega128 -o pr36901-2.s (timeout = 300) PASS: gcc.dg/pr36901-2.c (test for excess errors) Executing on host: /usr/local/avrdev/gcc/build/gcc/xgcc -B/usr/local/avrdev/gcc/build/gcc/ /usr/local/avrdev/gcc/gcc/gcc/testsuite/gcc.dg/pr36901-3.c -pedantic-errors -DSTACK_SIZE=2048 -DNO_TRAMPOLINES -fno-show-column -S -DSIGNAL_SUPPRESS -mmcu=atmega128 -o pr36901-3.s (timeout = 300) In file included from /usr/local/avrdev/gcc/gcc/gcc/testsuite/gcc.dg/pr36901-3.c:3: /usr/local/avrdev/gcc/gcc/gcc/testsuite/gcc.dg/pr36901.h:2: warning: integer overflow in expression /usr/local/avrdev/gcc/gcc/gcc/testsuite/gcc.dg/pr36901.h:2: error: overflow in constant expression compiler exited with status 1 output is: In file included from /usr/local/avrdev/gcc/gcc/gcc/testsuite/gcc.dg/pr36901-3.c:3: /usr/local/avrdev/gcc/gcc/gcc/testsuite/gcc.dg/pr36901.h:2: warning: integer overflow in expression /usr/local/avrdev/gcc/gcc/gcc/testsuite/gcc.dg/pr36901.h:2: error: overflow in constant expression PASS: gcc.dg/pr36901-3.c In file included (test for warnings, line ) PASS: gcc.dg/pr36901-3.c overflow (test for warnings, line ) PASS: gcc.dg/pr36901-3.c overflow (test for errors, line ) PASS: gcc.dg/pr36901-3.c (test for excess errors) Executing on host: /usr/local/avrdev/gcc/build/gcc/xgcc -B/usr/local/avrdev/gcc/build/gcc/ /usr/local/avrdev/gcc/gcc/gcc/testsuite/gcc.dg/pr36901-4.c -pedantic-errors -Wsystem-headers -DSTACK_SIZE=2048 -DNO_TRAMPOLINES -fno-show-column -S -DSIGNAL_SUPPRESS -mmcu=atmega128 -o pr36901-4.s (timeout = 300) In file included from /usr/local/avrdev/gcc/gcc/gcc/testsuite/gcc.dg/pr36901-4.c:3: /usr/local/avrdev/gcc/gcc/gcc/testsuite/gcc.dg/pr36901-system.h:2: error: #include_next is a GCC extension /usr/local/avrdev/gcc/gcc/gcc/testsuite/gcc.dg/pr36901-system.h:2: error: pr36901.h: No such file or directory /usr/local/avrdev/gcc/gcc/gcc/testsuite/gcc.dg/pr36901-4.c: In function 'foo': /usr/local/avrdev/gcc/gcc/gcc/testsuite/gcc.dg/pr36901-4.c:6: error: 'sc' undeclared (first use in this function) /usr/local/avrdev/gcc/gcc/gcc/testsuite/gcc.dg/pr36901-4.c:6: error: (Each undeclared identifier is reported only once /usr/local/avrdev/gcc/gcc/gcc/testsuite/gcc.dg/pr36901-4.c:6: error: for each function it appears in.) compiler exited with status 1 output is: In file included from /usr/local/avrdev/gcc/gcc/gcc/testsuite/gcc.dg/pr36901-4.c:3: /usr/local/avrdev/gcc/gcc/gcc/testsuite/gcc.dg/pr36901-system.h:2: error: #include_next is a GCC extension /usr/local/avrdev/gcc/gcc/gcc/testsuite/gcc.dg/pr36901-system.h:2: error: pr36901.h: No such file or directory /usr/local/avrdev/gcc/gcc/gcc/testsuite/gcc.dg/pr36901-4.c: In function 'foo': /usr/local/avrdev/gcc/gcc/gcc/testsuite/gcc.dg/pr36901-4.c:6: error: 'sc' undeclared (first use in this function) /usr/local/avrdev/gcc/gcc/gcc/testsuite/gcc.dg/pr36901-4.c:6: error: (Each undeclared identifier is reported only once /usr/local/avrdev/gcc/gcc/gcc/testsuite/gcc.dg/pr36901-4.c:6: error: for each function it appears in.) PASS: gcc.dg/pr36901-4.c In file included (test for warnings, line ) FAIL: gcc.dg/pr36901-4.c overflow (test for warnings, line ) FAIL: gcc.dg/pr36901-4.c overflow (test for errors, line ) PASS: gcc.dg/pr36901-4.c #include_next (test for errors, line ) FAIL: gcc.dg/pr36901-4.c (test for excess errors) Excess errors: /usr/local/avrdev/gcc/gcc/gcc/testsuite/gcc.dg/pr36901-system.h:2: error: pr36901.h: No such file or directory /usr/local/avrdev/gcc/gcc/gcc/testsuite/gcc.dg/pr36901-4.c:6: error: 'sc' undeclared (first use in this function) /usr/local/avrdev/gcc/gcc/gcc/testsuite/gcc.dg/pr36901-4.c:6: error: (Each undeclared identifier is reported only once /usr/local/avrdev/gcc/gcc/gcc/testsuite/gcc.dg/pr36901-4.c:6: error: for each function it appears in.)
Yeah, silly me, it obviously fails because there is no "next" pr36901.h to include. Since we include limits.h, we are at the mercy of the contents of the limits.h that is found. This isn't very reliable. We just need to a pedantic warning in the header. This works in x86_64, could you test on your side? Index: gcc/testsuite/gcc.dg/pr36901-3.c =================================================================== --- gcc/testsuite/gcc.dg/pr36901-3.c (revision 138906) +++ gcc/testsuite/gcc.dg/pr36901-3.c (working copy) @@ -4,7 +4,6 @@ void foo(void) { int s = sc; } /* { dg-message "file included" "In file included" { target *-*-* } 0 } */ -/* { dg-warning "overflow" "overflow" { target *-*-* } 0 } */ -/* { dg-error "overflow" "overflow" { target *-*-* } 0 } */ +/* { dg-error "ordered comparison of pointer with integer zero" "pedantic error" { target *-*-* } 0 } */ Index: gcc/testsuite/gcc.dg/pr36901-4.c =================================================================== --- gcc/testsuite/gcc.dg/pr36901-4.c (revision 138906) +++ gcc/testsuite/gcc.dg/pr36901-4.c (working copy) @@ -4,8 +4,6 @@ void foo(void) { int s = sc; } /* { dg-message "from " "In file included" { target *-*-* } 0 } */ -/* { dg-warning "overflow" "overflow" { target *-*-* } 0 } */ -/* { dg-error "overflow" "overflow" { target *-*-* } 0 } */ -/* { dg-error "#include_next is a GCC extension" "#include_next" { target *-*-* } 0 } */ +/* { dg-error "ordered comparison of pointer with integer zero" "pedantic error" { target *-*-* } 0 } */ Index: gcc/testsuite/gcc.dg/pr36901.h =================================================================== --- gcc/testsuite/gcc.dg/pr36901.h (revision 138906) +++ gcc/testsuite/gcc.dg/pr36901.h (working copy) @@ -1,2 +1,2 @@ -#include <limits.h> -static int sc = INT_MAX + 1; +int sc = (&sc > 0); +
(In reply to comment #10) > Since we include limits.h, we are at the mercy of the contents of the limits.h > that is found. This isn't very reliable. We just need to a pedantic warning in > the header. This works in x86_64, could you test on your side? Yes, this patch causes all of the tests to pass for the AVR. Thanks for working to find a solution for the AVR target.
Closing again.
Manuel, Note that I have *not committed* your patch to fix this. I don't have assignment papers done yet, nor do I have commit privs. You'll need to commit this to fix the problem.
Subject: Bug 36901 Author: manu Date: Sun Aug 10 18:32:52 2008 New Revision: 138932 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=138932 Log: 2008-08-10 Manuel Lopez-Ibanez <manu@gcc.gnu.org> PR 36901 testsuite/ * gcc.dg/pr36901.h: Do not depend on limits.h. * gcc.dg/pr36901-3.c: Update. * gcc.dg/pr36901-4.c: Update. Modified: trunk/gcc/testsuite/ChangeLog trunk/gcc/testsuite/gcc.dg/pr36901-3.c trunk/gcc/testsuite/gcc.dg/pr36901-4.c trunk/gcc/testsuite/gcc.dg/pr36901.h