diff options
author | manu <manu@138bc75d-0d04-0410-961f-82ee72b054a4> | 2008-08-08 23:57:19 +0000 |
---|---|---|
committer | manu <manu@138bc75d-0d04-0410-961f-82ee72b054a4> | 2008-08-08 23:57:19 +0000 |
commit | a52d5726b14e904406c69435e6b2955dfdb68735 (patch) | |
tree | 1c66246c77f4b33adec6eca15965b1e2f0bfa4bf /gcc/cp | |
parent | 6d8415dfcd06f712738a0ef683f11f3d50b9d356 (diff) | |
download | gcc-a52d5726b14e904406c69435e6b2955dfdb68735.tar.gz |
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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@138893 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/ChangeLog | 26 | ||||
-rw-r--r-- | gcc/cp/call.c | 32 | ||||
-rw-r--r-- | gcc/cp/cp-tree.h | 43 | ||||
-rw-r--r-- | gcc/cp/error.c | 2 | ||||
-rw-r--r-- | gcc/cp/friend.c | 8 | ||||
-rw-r--r-- | gcc/cp/init.c | 14 | ||||
-rw-r--r-- | gcc/cp/parser.c | 13 | ||||
-rw-r--r-- | gcc/cp/typeck.c | 2 | ||||
-rw-r--r-- | gcc/cp/typeck2.c | 71 |
9 files changed, 128 insertions, 83 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 46370908bec..8fd88428567 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,31 @@ 2008-08-09 Manuel Lopez-Ibanez <manu@gcc.gnu.org> + PR 36901 + * 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. + +2008-08-09 Manuel Lopez-Ibanez <manu@gcc.gnu.org> + PR 7651 * class.c (check_bases_and_members): Warn with -Wuninitialized instead of -Wextra. diff --git a/gcc/cp/call.c b/gcc/cp/call.c index cb07c82f1ab..2f6767388da 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -201,8 +201,7 @@ static void add_candidates (tree, tree, tree, bool, tree, tree, int, struct z_candidate **); static conversion *merge_conversion_sequences (conversion *, conversion *); static bool magic_varargs_p (tree); -typedef void (*diagnostic_fn_t) (const char *, ...) ATTRIBUTE_GCC_CXXDIAG(1,2); -static tree build_temp (tree, tree, int, diagnostic_fn_t *); +static tree build_temp (tree, tree, int, diagnostic_t *); /* Returns nonzero iff the destructor name specified in NAME matches BASETYPE. NAME can take many forms... */ @@ -4445,7 +4444,7 @@ enforce_access (tree basetype_path, tree decl, tree diag_decl) static tree build_temp (tree expr, tree type, int flags, - diagnostic_fn_t *diagnostic_fn) + diagnostic_t *diagnostic_kind) { int savew, savee; @@ -4455,11 +4454,11 @@ build_temp (tree expr, tree type, int flags, build_tree_list (NULL_TREE, expr), type, flags, tf_warning_or_error); if (warningcount > savew) - *diagnostic_fn = warning0; + *diagnostic_kind = DK_WARNING; else if (errorcount > savee) - *diagnostic_fn = error; + *diagnostic_kind = DK_ERROR; else - *diagnostic_fn = NULL; + *diagnostic_kind = 0; return expr; } @@ -4505,7 +4504,7 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum, bool c_cast_p, tsubst_flags_t complain) { tree totype = convs->type; - diagnostic_fn_t diagnostic_fn; + diagnostic_t diag_kind; int flags; if (convs->bad_p @@ -4682,12 +4681,13 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum, conversion (i.e. the second step of copy-initialization), so don't allow any more. */ flags |= LOOKUP_NO_CONVERSION; - expr = build_temp (expr, totype, flags, &diagnostic_fn); - if (diagnostic_fn && fn) + expr = build_temp (expr, totype, flags, &diag_kind); + if (diag_kind && fn) { if ((complain & tf_error)) - diagnostic_fn (" initializing argument %P of %qD", argnum, fn); - else if (diagnostic_fn == error) + emit_diagnostic (diag_kind, input_location, 0, + " initializing argument %P of %qD", argnum, fn); + else if (diag_kind == DK_ERROR) return error_mark_node; } return build_cplus_new (totype, expr); @@ -6647,10 +6647,12 @@ joust (struct z_candidate *cand1, struct z_candidate *cand2, bool warn) tree source = source_type (w->convs[0]); if (! DECL_CONSTRUCTOR_P (w->fn)) source = TREE_TYPE (source); - warning (OPT_Wconversion, "choosing %qD over %qD", w->fn, l->fn); - warning (OPT_Wconversion, " for conversion from %qT to %qT", - source, w->second_conv->type); - inform (" because conversion sequence for the argument is better"); + if (warning (OPT_Wconversion, "choosing %qD over %qD", w->fn, l->fn) + && warning (OPT_Wconversion, " for conversion from %qT to %qT", + source, w->second_conv->type)) + { + inform (" because conversion sequence for the argument is better"); + } } else add_warning (w, l); diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 02d358a8fe6..4b4bf335836 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -31,8 +31,28 @@ along with GCC; see the file COPYING3. If not see #include "varray.h" #include "c-common.h" #include "name-lookup.h" -struct diagnostic_context; -struct diagnostic_info; + +/* In order for the format checking to accept the C++ front end + diagnostic framework extensions, you must include this file before + toplev.h, not after. We override the definition of GCC_DIAG_STYLE + in c-common.h. */ +#undef GCC_DIAG_STYLE +#define GCC_DIAG_STYLE __gcc_cxxdiag__ +#if GCC_VERSION >= 4001 +#define ATTRIBUTE_GCC_CXXDIAG(m, n) __attribute__ ((__format__ (GCC_DIAG_STYLE, m, n))) ATTRIBUTE_NONNULL(m) +#else +#define ATTRIBUTE_GCC_CXXDIAG(m, n) ATTRIBUTE_NONNULL(m) +#endif +extern void cp_cpp_error (cpp_reader *, int, + const char *, va_list *) + ATTRIBUTE_GCC_CXXDIAG(3,0); +#ifdef GCC_TOPLEV_H +#error \ +"In order for the format checking to accept the C++ front end diagnostic\n" +"framework extensions, you must include this file before toplev.h, not after." +#endif +#include "toplev.h" +#include "diagnostic.h" /* Usage of TREE_LANG_FLAG_?: 0: IDENTIFIER_MARKED (IDENTIFIER_NODEs) @@ -4887,11 +4907,11 @@ extern int lvalue_p (const_tree); /* in typeck2.c */ extern void require_complete_eh_spec_types (tree, tree); -extern void cxx_incomplete_type_diagnostic (const_tree, const_tree, int); +extern void cxx_incomplete_type_diagnostic (const_tree, const_tree, diagnostic_t); #undef cxx_incomplete_type_error extern void cxx_incomplete_type_error (const_tree, const_tree); #define cxx_incomplete_type_error(V,T) \ - (cxx_incomplete_type_diagnostic ((V), (T), 0)) + (cxx_incomplete_type_diagnostic ((V), (T), DK_ERROR)) extern tree error_not_base_type (tree, tree); extern tree binfo_or_else (tree, tree); extern void readonly_error (tree, const char *); @@ -4945,19 +4965,4 @@ extern void cp_genericize (tree); /* -- end of C++ */ -/* In order for the format checking to accept the C++ front end - diagnostic framework extensions, you must include this file before - toplev.h, not after. We override the definition of GCC_DIAG_STYLE - in c-common.h. */ -#undef GCC_DIAG_STYLE -#define GCC_DIAG_STYLE __gcc_cxxdiag__ -#if GCC_VERSION >= 4001 -#define ATTRIBUTE_GCC_CXXDIAG(m, n) __attribute__ ((__format__ (GCC_DIAG_STYLE, m, n))) ATTRIBUTE_NONNULL(m) -#else -#define ATTRIBUTE_GCC_CXXDIAG(m, n) ATTRIBUTE_NONNULL(m) -#endif -extern void cp_cpp_error (cpp_reader *, int, - const char *, va_list *) - ATTRIBUTE_GCC_CXXDIAG(3,0); - #endif /* ! GCC_CP_TREE_H */ diff --git a/gcc/cp/error.c b/gcc/cp/error.c index ef26ad9114a..03ceddffb78 100644 --- a/gcc/cp/error.c +++ b/gcc/cp/error.c @@ -2661,7 +2661,7 @@ cp_cpp_error (cpp_reader *pfile ATTRIBUTE_UNUSED, int level, dlevel = DK_WARNING; break; case CPP_DL_PEDWARN: - dlevel = pedantic_warning_kind (); + dlevel = DK_PEDWARN; break; case CPP_DL_ERROR: dlevel = DK_ERROR; diff --git a/gcc/cp/friend.c b/gcc/cp/friend.c index 090f84db288..4d9a14ce88e 100644 --- a/gcc/cp/friend.c +++ b/gcc/cp/friend.c @@ -568,9 +568,11 @@ do_friend (tree ctype, tree declarator, tree decl, if (warn) { static int explained; - warning (OPT_Wnon_template_friend, "friend declaration " - "%q#D declares a non-template function", decl); - if (! explained) + bool warned; + + warned = warning (OPT_Wnon_template_friend, "friend declaration " + "%q#D declares a non-template function", decl); + if (! explained && warned) { inform ("(if this is not what you intended, make sure " "the function template has already been declared " diff --git a/gcc/cp/init.c b/gcc/cp/init.c index c6d63b84096..df36c5e829f 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -3035,12 +3035,14 @@ build_delete (tree type, tree addr, special_function_kind auto_delete, complete_type (type); if (!COMPLETE_TYPE_P (type)) { - warning (0, "possible problem detected in invocation of " - "delete operator:"); - cxx_incomplete_type_diagnostic (addr, type, 1); - inform ("neither the destructor nor the class-specific " - "operator delete will be called, even if they are " - "declared when the class is defined."); + if (warning (0, "possible problem detected in invocation of " + "delete operator:")) + { + cxx_incomplete_type_diagnostic (addr, type, DK_WARNING); + inform ("neither the destructor nor the class-specific " + "operator delete will be called, even if they are " + "declared when the class is defined."); + } complete_p = false; } } diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 7c1b04d5d04..1bb52e5e01c 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -9980,15 +9980,14 @@ cp_parser_template_id (cp_parser *parser, } /* Otherwise, emit an error about the invalid digraph, but continue parsing because we got our argument list. */ - permerror ("%H%<<::%> cannot begin a template-argument list", - &next_token->location); - inform ("%H%<<:%> is an alternate spelling for %<[%>. Insert whitespace " + if (permerror ("%H%<<::%> cannot begin a template-argument list", + &next_token->location)) + { + static bool hint = false; + inform ("%H%<<:%> is an alternate spelling for %<[%>. Insert whitespace " "between %<<%> and %<::%>", &next_token->location); - if (!flag_permissive) - { - static bool hint; - if (!hint) + if (!hint && !flag_permissive) { inform ("%H(if you use %<-fpermissive%> G++ will accept your code)", &next_token->location); diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 792a77cc1a8..a99526f1318 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -145,7 +145,7 @@ complete_type_or_else (tree type, tree value) return NULL_TREE; else if (!COMPLETE_TYPE_P (type)) { - cxx_incomplete_type_diagnostic (value, type, 0); + cxx_incomplete_type_diagnostic (value, type, DK_ERROR); return NULL_TREE; } else diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c index 787f43963d6..bca95e970f1 100644 --- a/gcc/cp/typeck2.c +++ b/gcc/cp/typeck2.c @@ -332,22 +332,18 @@ abstract_virtuals_error (tree decl, tree type) /* Print an error message for invalid use of an incomplete type. VALUE is the expression that was used (or 0 if that isn't known) - and TYPE is the type that was invalid. DIAG_TYPE indicates the - type of diagnostic: 0 for an error, 1 for a warning, 2 for a - pedwarn. */ + and TYPE is the type that was invalid. DIAG_KIND indicates the + type of diagnostic (see diagnostic.def). */ void -cxx_incomplete_type_diagnostic (const_tree value, const_tree type, int diag_type) +cxx_incomplete_type_diagnostic (const_tree value, const_tree type, + diagnostic_t diag_kind) { int decl = 0; - void (*p_msg) (const char *, ...) ATTRIBUTE_GCC_CXXDIAG(1,2); - if (diag_type == 1) - p_msg = warning0; - else if (diag_type == 2) - p_msg = pedwarn0; - else - p_msg = error; + gcc_assert (diag_kind == DK_WARNING + || diag_kind == DK_PEDWARN + || diag_kind == DK_ERROR); /* Avoid duplicate error message. */ if (TREE_CODE (type) == ERROR_MARK) @@ -357,7 +353,8 @@ cxx_incomplete_type_diagnostic (const_tree value, const_tree type, int diag_type || TREE_CODE (value) == PARM_DECL || TREE_CODE (value) == FIELD_DECL)) { - p_msg ("%q+D has incomplete type", value); + emit_diagnostic (diag_kind, input_location, 0, + "%q+D has incomplete type", value); decl = 1; } retry: @@ -369,15 +366,19 @@ cxx_incomplete_type_diagnostic (const_tree value, const_tree type, int diag_type case UNION_TYPE: case ENUMERAL_TYPE: if (!decl) - p_msg ("invalid use of incomplete type %q#T", type); + emit_diagnostic (diag_kind, input_location, 0, + "invalid use of incomplete type %q#T", type); if (!TYPE_TEMPLATE_INFO (type)) - p_msg ("forward declaration of %q+#T", type); + emit_diagnostic (diag_kind, input_location, 0, + "forward declaration of %q+#T", type); else - p_msg ("declaration of %q+#T", type); + emit_diagnostic (diag_kind, input_location, 0, + "declaration of %q+#T", type); break; case VOID_TYPE: - p_msg ("invalid use of %qT", type); + emit_diagnostic (diag_kind, input_location, 0, + "invalid use of %qT", type); break; case ARRAY_TYPE: @@ -386,37 +387,45 @@ cxx_incomplete_type_diagnostic (const_tree value, const_tree type, int diag_type type = TREE_TYPE (type); goto retry; } - p_msg ("invalid use of array with unspecified bounds"); + emit_diagnostic (diag_kind, input_location, 0, + "invalid use of array with unspecified bounds"); break; case OFFSET_TYPE: bad_member: - p_msg ("invalid use of member (did you forget the %<&%> ?)"); + emit_diagnostic (diag_kind, input_location, 0, + "invalid use of member (did you forget the %<&%> ?)"); break; case TEMPLATE_TYPE_PARM: - p_msg ("invalid use of template type parameter %qT", type); + emit_diagnostic (diag_kind, input_location, 0, + "invalid use of template type parameter %qT", type); break; case BOUND_TEMPLATE_TEMPLATE_PARM: - p_msg ("invalid use of template template parameter %qT", - TYPE_NAME (type)); + emit_diagnostic (diag_kind, input_location, 0, + "invalid use of template template parameter %qT", + TYPE_NAME (type)); break; case TYPENAME_TYPE: - p_msg ("invalid use of dependent type %qT", type); + emit_diagnostic (diag_kind, input_location, 0, + "invalid use of dependent type %qT", type); break; case UNKNOWN_TYPE: if (value && TREE_CODE (value) == COMPONENT_REF) goto bad_member; else if (value && TREE_CODE (value) == ADDR_EXPR) - p_msg ("address of overloaded function with no contextual " - "type information"); + emit_diagnostic (diag_kind, input_location, 0, + "address of overloaded function with no contextual " + "type information"); else if (value && TREE_CODE (value) == OVERLOAD) - p_msg ("overloaded function with no contextual type information"); + emit_diagnostic (diag_kind, input_location, 0, + "overloaded function with no contextual type information"); else - p_msg ("insufficient contextual information to determine type"); + emit_diagnostic (diag_kind, input_location, 0, + "insufficient contextual information to determine type"); break; default: @@ -430,7 +439,7 @@ cxx_incomplete_type_diagnostic (const_tree value, const_tree type, int diag_type void cxx_incomplete_type_error (const_tree value, const_tree type) { - cxx_incomplete_type_diagnostic (value, type, 0); + cxx_incomplete_type_diagnostic (value, type, DK_ERROR); } @@ -1483,7 +1492,7 @@ add_exception_specifier (tree list, tree spec, int complain) bool ok; tree core = spec; bool is_ptr; - int diag_type = -1; /* none */ + diagnostic_t diag_type = DK_UNSPECIFIED; /* none */ if (spec == error_mark_node) return list; @@ -1512,7 +1521,7 @@ add_exception_specifier (tree list, tree spec, int complain) and calls. So just give a pedwarn at this point; we will give an error later if we hit one of those two cases. */ if (!COMPLETE_TYPE_P (complete_type (core))) - diag_type = 2; /* pedwarn */ + diag_type = DK_PEDWARN; /* pedwarn */ } if (ok) @@ -1526,9 +1535,9 @@ add_exception_specifier (tree list, tree spec, int complain) list = tree_cons (NULL_TREE, spec, list); } else - diag_type = 0; /* error */ + diag_type = DK_ERROR; /* error */ - if (diag_type >= 0 && complain) + if (diag_type != DK_UNSPECIFIED && complain) cxx_incomplete_type_diagnostic (NULL_TREE, core, diag_type); return list; |