[C/C++/Fortran] remove pedwarn0 and warning0 and fix PR 36901

Manuel López-Ibáñez lopezibanez@gmail.com
Mon Aug 4 17:10:00 GMT 2008


So in order to fix a patch I had already I was forced to fix all this.
And the issues are so intertwined that I needed to fix several
seemingly unrelated aspects to make this work. I did try to fix each
of them separately but it would require ugly work-arounds to make the
intermediate steps work

This patch:

* Removes the few uses of pedwarn0 and warning0. If a function needs
to emit a custom diagnostic depending on some condition and it doesn't
want to duplicate code, it should use the new generic emit_diagnostic
function.

* Functions that can fail (such as warning, pedwarn and permerror) now
return a boolean indicating whether they actually emitted a diagnostic
or it was inhibited. This allows to correctly chain diagnostics and
informative notes. I have updated a few obvious places in the code but
surely there are other places where we do tricks to know if the
warning was inhibited. Those tricks are very fragile. Checking the
return value of the diagnostic function is more robust. One question:
this patch enables to do

warning ("a warning that may not get emitted") && inform ("a note
about the warning");

however I have avoided such constructs in favour of explicit "if" but
perhaps the above is shorter, faster and/or clearer. What do you
think?

* It adds two new diagnostics kinds: DK_PEDWARN and DK_PERMERROR.
These make easier to write emit_diagnostic and simplifies other code:
no need for custom codes "int diag_type", use directly a diagnostic_t
diag_type and the codes from diagnostic.def.

* DK_PEDWARN and DK_PERMERROR are re-classified to DK_WARNING and
DK_ERROR within diagnostic_report_diagnostic. This means that they can
be properly inhibited by "-w" and within system headers. In
particular, DK_PEDWARN is inhibited before being reclassified, thus
diagnostics triggered by -pedantic-errors are inhibited within system
headers and by "-w". On the other hand, DK_PERMERROR is inhibited
after being reclassified, hence errors show up always but when relaxed
to warnings by -fpermissive, they can be inhibited. This effectively
fixes PR 36901.

* locate_old_decl now always prints "note: previous definition of %q+D
was here" instead of "error:" or "warning:".


The last one means that a lot of testcases needed updating. I did it
mostly mechanically with sed.

I have separated the patch into the main stuff and the updates to the
testsuite.

2008-08-04  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.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: fix-pr36901.diff
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20080804/530ad646/attachment.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: fix-pr36901-testsuite.diff
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20080804/530ad646/attachment-0001.ksh>


More information about the Gcc-patches mailing list