aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/cp')
-rw-r--r--gcc/cp/ChangeLog26
-rw-r--r--gcc/cp/call.c32
-rw-r--r--gcc/cp/cp-tree.h43
-rw-r--r--gcc/cp/error.c2
-rw-r--r--gcc/cp/friend.c8
-rw-r--r--gcc/cp/init.c14
-rw-r--r--gcc/cp/parser.c13
-rw-r--r--gcc/cp/typeck.c2
-rw-r--r--gcc/cp/typeck2.c71
9 files changed, 128 insertions, 83 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 4637090..8fd8842 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 cb07c82..2f67673 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 02d358a..4b4bf33 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 ef26ad9..03ceddf 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 090f84d..4d9a14c 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 c6d63b8..df36c5e 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 7c1b04d..1bb52e5 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 792a77c..a99526f 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 787f439..bca95e9 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;