diff options
author | Manuel López-Ibáñez <manu@gcc.gnu.org> | 2008-08-08 23:57:19 +0000 |
---|---|---|
committer | Manuel López-Ibáñez <manu@gcc.gnu.org> | 2008-08-08 23:57:19 +0000 |
commit | 71205d170c59ae70323aa7d0b93ff5c13044fd57 (patch) | |
tree | 1c66246c77f4b33adec6eca15965b1e2f0bfa4bf /gcc/diagnostic.c | |
parent | c73d5dd948d68fb2550f7d178d1483aebcfbcaea (diff) | |
download | gcc-71205d170c59ae70323aa7d0b93ff5c13044fd57.zip gcc-71205d170c59ae70323aa7d0b93ff5c13044fd57.tar.gz gcc-71205d170c59ae70323aa7d0b93ff5c13044fd57.tar.bz2 |
re PR other/36901 (pedwarn() + -pedantic-errors + -w (inhibit_warnings) should not emit errors)
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.
From-SVN: r138893
Diffstat (limited to 'gcc/diagnostic.c')
-rw-r--r-- | gcc/diagnostic.c | 111 |
1 files changed, 61 insertions, 50 deletions
diff --git a/gcc/diagnostic.c b/gcc/diagnostic.c index 69b7e4b..cb4c67a 100644 --- a/gcc/diagnostic.c +++ b/gcc/diagnostic.c @@ -41,6 +41,8 @@ along with GCC; see the file COPYING3. If not see #include "langhooks-def.h" #include "opts.h" +#define pedantic_warning_kind() (flag_pedantic_errors ? DK_ERROR : DK_WARNING) +#define permissive_error_kind() (flag_permissive ? DK_WARNING : DK_ERROR) /* Prototypes. */ static char *build_message_string (const char *, ...) ATTRIBUTE_PRINTF_1; @@ -293,9 +295,10 @@ diagnostic_classify_diagnostic (diagnostic_context *context, DC. This function is *the* subroutine in terms of which front-ends should implement their specific diagnostic handling modules. The front-end independent format specifiers are exactly those described - in the documentation of output_format. */ + in the documentation of output_format. + Return true if a diagnostic was printed, false otherwise. */ -void +bool diagnostic_report_diagnostic (diagnostic_context *context, diagnostic_info *diagnostic) { @@ -305,9 +308,12 @@ diagnostic_report_diagnostic (diagnostic_context *context, /* Give preference to being able to inhibit warnings, before they get reclassified to something else. */ - if (diagnostic->kind == DK_WARNING + if ((diagnostic->kind == DK_WARNING || diagnostic->kind == DK_PEDWARN) && !diagnostic_report_warnings_p (location)) - return; + return false; + + if (diagnostic->kind == DK_PEDWARN) + diagnostic->kind = pedantic_warning_kind (); if (context->lock > 0) { @@ -336,7 +342,7 @@ diagnostic_report_diagnostic (diagnostic_context *context, /* This tests if the user provided the appropriate -Wfoo or -Wno-foo option. */ if (! option_enabled (diagnostic->option_index)) - return; + return false; /* This tests if the user provided the appropriate -Werror=foo option. */ if (context->classify_diagnostic[diagnostic->option_index] != DK_UNSPECIFIED) @@ -347,7 +353,7 @@ diagnostic_report_diagnostic (diagnostic_context *context, /* This allows for future extensions, like temporarily disabling warnings for ranges of source code. */ if (diagnostic->kind == DK_IGNORED) - return; + return false; } /* If we changed the kind due to -Werror, and didn't override it, we @@ -403,6 +409,8 @@ diagnostic_report_diagnostic (diagnostic_context *context, diagnostic->abstract_origin = NULL; context->lock--; + + return true; } /* Given a partial pathname as input, return another pathname that @@ -457,51 +465,66 @@ verbatim (const char *gmsgid, ...) va_end (ap); } -/* An informative note. Use this for additional details on an error - message. */ -void -inform (const char *gmsgid, ...) +bool +emit_diagnostic (diagnostic_t kind, location_t location, int opt, + const char *gmsgid, ...) { diagnostic_info diagnostic; va_list ap; va_start (ap, gmsgid); - diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location, DK_NOTE); - report_diagnostic (&diagnostic); + if (kind == DK_PERMERROR) + { + diagnostic_set_info (&diagnostic, gmsgid, &ap, location, + permissive_error_kind ()); + diagnostic.option_index = OPT_fpermissive; + } + else { + diagnostic_set_info (&diagnostic, gmsgid, &ap, location, kind); + if (kind == DK_WARNING || kind == DK_PEDWARN) + diagnostic.option_index = opt; + } va_end (ap); + + return report_diagnostic (&diagnostic); } -/* A warning at INPUT_LOCATION. Use this for code which is correct according - to the relevant language specification but is likely to be buggy anyway. */ +/* An informative note. Use this for additional details on an error + message. */ void -warning (int opt, const char *gmsgid, ...) +inform (const char *gmsgid, ...) { diagnostic_info diagnostic; va_list ap; va_start (ap, gmsgid); - diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location, DK_WARNING); - diagnostic.option_index = opt; - + diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location, DK_NOTE); report_diagnostic (&diagnostic); va_end (ap); } -void -warning0 (const char *gmsgid, ...) +/* A warning at INPUT_LOCATION. Use this for code which is correct according + to the relevant language specification but is likely to be buggy anyway. + Returns true if the warning was printed, false if it was inhibited. */ +bool +warning (int opt, const char *gmsgid, ...) { diagnostic_info diagnostic; va_list ap; va_start (ap, gmsgid); diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location, DK_WARNING); - report_diagnostic (&diagnostic); + diagnostic.option_index = opt; + va_end (ap); + return report_diagnostic (&diagnostic); } /* A warning at LOCATION. Use this for code which is correct according to the - relevant language specification but is likely to be buggy anyway. */ -void + relevant language specification but is likely to be buggy anyway. + Returns true if the warning was printed, false if it was inhibited. */ + +bool warning_at (location_t location, int opt, const char *gmsgid, ...) { diagnostic_info diagnostic; @@ -510,9 +533,8 @@ warning_at (location_t location, int opt, const char *gmsgid, ...) va_start (ap, gmsgid); diagnostic_set_info (&diagnostic, gmsgid, &ap, location, DK_WARNING); diagnostic.option_index = opt; - - report_diagnostic (&diagnostic); va_end (ap); + return report_diagnostic (&diagnostic); } /* A "pedantic" warning: issues a warning unless -pedantic-errors was @@ -524,42 +546,31 @@ warning_at (location_t location, int opt, const char *gmsgid, ...) of the -pedantic command-line switch. To get a warning enabled only with that switch, use either "if (pedantic) pedwarn (OPT_pedantic,...)" or just "pedwarn (OPT_pedantic,..)". To get a - pedwarn independently of the -pedantic switch use "pedwarn (0,...)". */ + pedwarn independently of the -pedantic switch use "pedwarn (0,...)". -void + Returns true if the warning was printed, false if it was inhibited. */ + +bool pedwarn (int opt, const char *gmsgid, ...) { diagnostic_info diagnostic; va_list ap; va_start (ap, gmsgid); - diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location, - pedantic_warning_kind ()); + diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location, DK_PEDWARN); diagnostic.option_index = opt; - - report_diagnostic (&diagnostic); - va_end (ap); -} - -void -pedwarn0 (const char *gmsgid, ...) -{ - diagnostic_info diagnostic; - va_list ap; - - va_start (ap, gmsgid); - diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location, - pedantic_warning_kind ()); - report_diagnostic (&diagnostic); va_end (ap); + return report_diagnostic (&diagnostic); } /* A "permissive" error at LOCATION: issues an error unless -fpermissive was given on the command line, in which case it issues a warning. Use this for things that really should be errors but we - want to support legacy code. */ + want to support legacy code. -void + Returns true if the warning was printed, false if it was inhibited. */ + +bool permerror_at (location_t location, const char *gmsgid, ...) { diagnostic_info diagnostic; @@ -567,15 +578,15 @@ permerror_at (location_t location, const char *gmsgid, ...) va_start (ap, gmsgid); diagnostic_set_info (&diagnostic, gmsgid, &ap, location, - permissive_error_kind ()); + permissive_error_kind ()); diagnostic.option_index = OPT_fpermissive; - report_diagnostic (&diagnostic); va_end (ap); + return report_diagnostic (&diagnostic); } /* Equivalent to permerror_at (input_location, ...). */ -void +bool permerror (const char *gmsgid, ...) { diagnostic_info diagnostic; @@ -585,8 +596,8 @@ permerror (const char *gmsgid, ...) diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location, permissive_error_kind ()); diagnostic.option_index = OPT_fpermissive; - report_diagnostic (&diagnostic); va_end (ap); + return report_diagnostic (&diagnostic); } |