Commit 15827d12 by Paolo Carlini Committed by Paolo Carlini

class.c (check_for_override): Use DECL_SOURCE_LOCATION and "%qD" in warning_at…

class.c (check_for_override): Use DECL_SOURCE_LOCATION and "%qD" in warning_at instead of "%q+D" in warning.

2015-07-30  Paolo Carlini  <paolo.carlini@oracle.com>

	* class.c (check_for_override): Use DECL_SOURCE_LOCATION and "%qD"
	in warning_at instead of "%q+D" in warning.
	(warn_hidden): Likewise but use location_of.
	(finish_struct_anon_r): Likewise use DECL_SOURCE_LOCATION in permerror.
	(check_bitfield_decl, check_field_decls): Likewise in warning_at.
	(check_field_decls): Likewise for permerror.
	(explain_non_literal_class): Likewise for inform.
	(check_bases_and_members, layout_class_type): Likewise for warning_at.
	(note_name_declared_in_class): Use location_of in permerror.
	* name-lookup.c (diagnose_name_conflict): Use location_of in inform.
	(pushdecl_maybe_friend_1): Use DECL_SOURCE_LOCATION in pedwarn,
	inform, and warning_at.
	(check_for_out_of_scope_variable): Likewise for warning_at and
	permerror.

From-SVN: r226394
parent 2e3f48dc
2015-07-30 Paolo Carlini <paolo.carlini@oracle.com>
* class.c (check_for_override): Use DECL_SOURCE_LOCATION and "%qD"
in warning_at instead of "%q+D" in warning.
(warn_hidden): Likewise but use location_of.
(finish_struct_anon_r): Likewise use DECL_SOURCE_LOCATION in permerror.
(check_bitfield_decl, check_field_decls): Likewise in warning_at.
(check_field_decls): Likewise for permerror.
(explain_non_literal_class): Likewise for inform.
(check_bases_and_members, layout_class_type): Likewise for warning_at.
(note_name_declared_in_class): Use location_of in permerror.
* name-lookup.c (diagnose_name_conflict): Use location_of in inform.
(pushdecl_maybe_friend_1): Use DECL_SOURCE_LOCATION in pedwarn,
inform, and warning_at.
(check_for_out_of_scope_variable): Likewise for warning_at and
permerror.
2015-07-30 Jason Merrill <jason@redhat.com> 2015-07-30 Jason Merrill <jason@redhat.com>
DR 1558 DR 1558
......
...@@ -2926,7 +2926,7 @@ check_for_override (tree decl, tree ctype) ...@@ -2926,7 +2926,7 @@ check_for_override (tree decl, tree ctype)
if (warn_override && !DECL_OVERRIDE_P (decl) if (warn_override && !DECL_OVERRIDE_P (decl)
&& !DECL_DESTRUCTOR_P (decl)) && !DECL_DESTRUCTOR_P (decl))
warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wsuggest_override, warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wsuggest_override,
"%q+D can be marked override", decl); "%qD can be marked override", decl);
} }
if (DECL_VIRTUAL_P (decl)) if (DECL_VIRTUAL_P (decl))
...@@ -3008,8 +3008,11 @@ warn_hidden (tree t) ...@@ -3008,8 +3008,11 @@ warn_hidden (tree t)
if (base_fndecl) if (base_fndecl)
{ {
/* Here we know it is a hider, and no overrider exists. */ /* Here we know it is a hider, and no overrider exists. */
warning (OPT_Woverloaded_virtual, "%q+D was hidden", base_fndecl); warning_at (location_of (base_fndecl),
warning (OPT_Woverloaded_virtual, " by %q+D", fns); OPT_Woverloaded_virtual,
"%qD was hidden", base_fndecl);
warning_at (location_of (fns),
OPT_Woverloaded_virtual, " by %qD", fns);
} }
} }
} }
...@@ -3042,12 +3045,12 @@ finish_struct_anon_r (tree field, bool complain) ...@@ -3042,12 +3045,12 @@ finish_struct_anon_r (tree field, bool complain)
if (complain && !VAR_P (elt)) if (complain && !VAR_P (elt))
{ {
if (is_union) if (is_union)
permerror (input_location, permerror (DECL_SOURCE_LOCATION (elt),
"%q+#D invalid; an anonymous union can " "%q#D invalid; an anonymous union can "
"only have non-static data members", elt); "only have non-static data members", elt);
else else
permerror (input_location, permerror (DECL_SOURCE_LOCATION (elt),
"%q+#D invalid; an anonymous struct can " "%q#D invalid; an anonymous struct can "
"only have non-static data members", elt); "only have non-static data members", elt);
} }
continue; continue;
...@@ -3058,20 +3061,20 @@ finish_struct_anon_r (tree field, bool complain) ...@@ -3058,20 +3061,20 @@ finish_struct_anon_r (tree field, bool complain)
if (TREE_PRIVATE (elt)) if (TREE_PRIVATE (elt))
{ {
if (is_union) if (is_union)
permerror (input_location, permerror (DECL_SOURCE_LOCATION (elt),
"private member %q+#D in anonymous union", elt); "private member %q#D in anonymous union", elt);
else else
permerror (input_location, permerror (DECL_SOURCE_LOCATION (elt),
"private member %q+#D in anonymous struct", elt); "private member %q#D in anonymous struct", elt);
} }
else if (TREE_PROTECTED (elt)) else if (TREE_PROTECTED (elt))
{ {
if (is_union) if (is_union)
permerror (input_location, permerror (DECL_SOURCE_LOCATION (elt),
"protected member %q+#D in anonymous union", elt); "protected member %q#D in anonymous union", elt);
else else
permerror (input_location, permerror (DECL_SOURCE_LOCATION (elt),
"protected member %q+#D in anonymous struct", elt); "protected member %q#D in anonymous struct", elt);
} }
} }
...@@ -3460,11 +3463,14 @@ check_bitfield_decl (tree field) ...@@ -3460,11 +3463,14 @@ check_bitfield_decl (tree field)
|| ((TREE_CODE (type) == ENUMERAL_TYPE || ((TREE_CODE (type) == ENUMERAL_TYPE
|| TREE_CODE (type) == BOOLEAN_TYPE) || TREE_CODE (type) == BOOLEAN_TYPE)
&& tree_int_cst_lt (TYPE_SIZE (type), w))) && tree_int_cst_lt (TYPE_SIZE (type), w)))
warning (0, "width of %q+D exceeds its type", field); warning_at (DECL_SOURCE_LOCATION (field), 0,
"width of %qD exceeds its type", field);
else if (TREE_CODE (type) == ENUMERAL_TYPE else if (TREE_CODE (type) == ENUMERAL_TYPE
&& (0 > (compare_tree_int && (0 > (compare_tree_int
(w, TYPE_PRECISION (ENUM_UNDERLYING_TYPE (type)))))) (w, TYPE_PRECISION (ENUM_UNDERLYING_TYPE (type))))))
warning (0, "%q+D is too small to hold all values of %q#T", field, type); warning_at (DECL_SOURCE_LOCATION (field), 0,
"%qD is too small to hold all values of %q#T",
field, type);
} }
if (w != error_mark_node) if (w != error_mark_node)
...@@ -3737,9 +3743,9 @@ check_field_decls (tree t, tree *access_decls, ...@@ -3737,9 +3743,9 @@ check_field_decls (tree t, tree *access_decls,
{ {
if (!layout_pod_type_p (type) && !TYPE_PACKED (type)) if (!layout_pod_type_p (type) && !TYPE_PACKED (type))
{ {
warning warning_at
(0, (DECL_SOURCE_LOCATION (x), 0,
"ignoring packed attribute because of unpacked non-POD field %q+#D", "ignoring packed attribute because of unpacked non-POD field %q#D",
x); x);
cant_pack = 1; cant_pack = 1;
} }
...@@ -3854,7 +3860,8 @@ check_field_decls (tree t, tree *access_decls, ...@@ -3854,7 +3860,8 @@ check_field_decls (tree t, tree *access_decls,
user-declared constructor. */ user-declared constructor. */
if (constructor_name_p (DECL_NAME (x), t) if (constructor_name_p (DECL_NAME (x), t)
&& TYPE_HAS_USER_CONSTRUCTOR (t)) && TYPE_HAS_USER_CONSTRUCTOR (t))
permerror (input_location, "field %q+#D with same name as class", x); permerror (DECL_SOURCE_LOCATION (x),
"field %q#D with same name as class", x);
} }
/* Effective C++ rule 11: if a class has dynamic memory held by pointers, /* Effective C++ rule 11: if a class has dynamic memory held by pointers,
...@@ -5623,14 +5630,15 @@ explain_non_literal_class (tree t) ...@@ -5623,14 +5630,15 @@ explain_non_literal_class (tree t)
ftype = TREE_TYPE (field); ftype = TREE_TYPE (field);
if (!literal_type_p (ftype)) if (!literal_type_p (ftype))
{ {
inform (0, " non-static data member %q+D has " inform (DECL_SOURCE_LOCATION (field),
"non-literal type", field); " non-static data member %qD has non-literal type",
field);
if (CLASS_TYPE_P (ftype)) if (CLASS_TYPE_P (ftype))
explain_non_literal_class (ftype); explain_non_literal_class (ftype);
} }
if (CP_TYPE_VOLATILE_P (ftype)) if (CP_TYPE_VOLATILE_P (ftype))
inform (0, " non-static data member %q+D has " inform (DECL_SOURCE_LOCATION (field),
"volatile type", field); " non-static data member %qD has volatile type", field);
} }
} }
} }
...@@ -5775,12 +5783,14 @@ check_bases_and_members (tree t) ...@@ -5775,12 +5783,14 @@ check_bases_and_members (tree t)
type = TREE_TYPE (field); type = TREE_TYPE (field);
if (TREE_CODE (type) == REFERENCE_TYPE) if (TREE_CODE (type) == REFERENCE_TYPE)
warning (OPT_Wuninitialized, "non-static reference %q+#D " warning_at (DECL_SOURCE_LOCATION (field),
OPT_Wuninitialized, "non-static reference %q#D "
"in class without a constructor", field); "in class without a constructor", field);
else if (CP_TYPE_CONST_P (type) else if (CP_TYPE_CONST_P (type)
&& (!CLASS_TYPE_P (type) && (!CLASS_TYPE_P (type)
|| !TYPE_HAS_DEFAULT_CONSTRUCTOR (type))) || !TYPE_HAS_DEFAULT_CONSTRUCTOR (type)))
warning (OPT_Wuninitialized, "non-static const member %q+#D " warning_at (DECL_SOURCE_LOCATION (field),
OPT_Wuninitialized, "non-static const member %q#D "
"in class without a constructor", field); "in class without a constructor", field);
} }
} }
...@@ -6322,7 +6332,8 @@ layout_class_type (tree t, tree *virtuals_p) ...@@ -6322,7 +6332,8 @@ layout_class_type (tree t, tree *virtuals_p)
&& !integer_zerop (size_binop (TRUNC_MOD_EXPR, && !integer_zerop (size_binop (TRUNC_MOD_EXPR,
DECL_FIELD_BIT_OFFSET (field), DECL_FIELD_BIT_OFFSET (field),
bitsize_unit_node))) bitsize_unit_node)))
warning (OPT_Wabi, "offset of %q+D is not ABI-compliant and may " warning_at (DECL_SOURCE_LOCATION (field), OPT_Wabi,
"offset of %qD is not ABI-compliant and may "
"change in a future version of GCC", field); "change in a future version of GCC", field);
/* The middle end uses the type of expressions to determine the /* The middle end uses the type of expressions to determine the
...@@ -8113,7 +8124,8 @@ note_name_declared_in_class (tree name, tree decl) ...@@ -8113,7 +8124,8 @@ note_name_declared_in_class (tree name, tree decl)
in its context and when re-evaluated in the completed scope of in its context and when re-evaluated in the completed scope of
S. */ S. */
permerror (input_location, "declaration of %q#D", decl); permerror (input_location, "declaration of %q#D", decl);
permerror (input_location, "changes meaning of %qD from %q+#D", permerror (location_of ((tree) n->value),
"changes meaning of %qD from %q#D",
DECL_NAME (OVL_CURRENT (decl)), (tree) n->value); DECL_NAME (OVL_CURRENT (decl)), (tree) n->value);
} }
} }
......
...@@ -590,7 +590,7 @@ diagnose_name_conflict (tree decl, tree bval) ...@@ -590,7 +590,7 @@ diagnose_name_conflict (tree decl, tree bval)
else else
error ("%q#D conflicts with a previous declaration", decl); error ("%q#D conflicts with a previous declaration", decl);
inform (input_location, "previous declaration %q+#D", bval); inform (location_of (bval), "previous declaration %q#D", bval);
} }
/* Wrapper for supplement_binding_1. */ /* Wrapper for supplement_binding_1. */
...@@ -875,8 +875,8 @@ pushdecl_maybe_friend_1 (tree x, bool is_friend) ...@@ -875,8 +875,8 @@ pushdecl_maybe_friend_1 (tree x, bool is_friend)
pedwarn (input_location, 0, pedwarn (input_location, 0,
"declaration of %q#D with C language linkage", "declaration of %q#D with C language linkage",
x); x);
pedwarn (input_location, 0, pedwarn (DECL_SOURCE_LOCATION (previous), 0,
"conflicts with previous declaration %q+#D", "conflicts with previous declaration %q#D",
previous); previous);
pedwarn (input_location, 0, pedwarn (input_location, 0,
"due to different exception specifications"); "due to different exception specifications");
...@@ -890,8 +890,8 @@ pushdecl_maybe_friend_1 (tree x, bool is_friend) ...@@ -890,8 +890,8 @@ pushdecl_maybe_friend_1 (tree x, bool is_friend)
{ {
pedwarn (input_location, 0, pedwarn (input_location, 0,
"declaration of %q#D with C language linkage", x); "declaration of %q#D with C language linkage", x);
pedwarn (input_location, 0, pedwarn (DECL_SOURCE_LOCATION (previous), 0,
"conflicts with previous declaration %q+#D", "conflicts with previous declaration %q#D",
previous); previous);
} }
} }
...@@ -992,8 +992,8 @@ pushdecl_maybe_friend_1 (tree x, bool is_friend) ...@@ -992,8 +992,8 @@ pushdecl_maybe_friend_1 (tree x, bool is_friend)
{ {
if (permerror (input_location, "type mismatch with previous " if (permerror (input_location, "type mismatch with previous "
"external decl of %q#D", x)) "external decl of %q#D", x))
inform (input_location, "previous external decl of %q+#D", inform (DECL_SOURCE_LOCATION (decl),
decl); "previous external decl of %q#D", decl);
} }
} }
...@@ -1082,7 +1082,8 @@ pushdecl_maybe_friend_1 (tree x, bool is_friend) ...@@ -1082,7 +1082,8 @@ pushdecl_maybe_friend_1 (tree x, bool is_friend)
else else
{ {
warning (0, "extern declaration of %q#D doesn%'t match", x); warning (0, "extern declaration of %q#D doesn%'t match", x);
warning (0, "global declaration %q+#D", oldglobal); warning_at (DECL_SOURCE_LOCATION (oldglobal), 0,
"global declaration %q#D", oldglobal);
} }
} }
/* If we have a local external declaration, /* If we have a local external declaration,
...@@ -1170,8 +1171,8 @@ pushdecl_maybe_friend_1 (tree x, bool is_friend) ...@@ -1170,8 +1171,8 @@ pushdecl_maybe_friend_1 (tree x, bool is_friend)
|| oldscope->kind == sk_for)) || oldscope->kind == sk_for))
{ {
error ("redeclaration of %q#D", x); error ("redeclaration of %q#D", x);
inform (input_location, "%q+#D previously declared here", inform (DECL_SOURCE_LOCATION (oldlocal),
oldlocal); "%q#D previously declared here", oldlocal);
nowarn = true; nowarn = true;
} }
/* C++11: /* C++11:
...@@ -1193,8 +1194,8 @@ pushdecl_maybe_friend_1 (tree x, bool is_friend) ...@@ -1193,8 +1194,8 @@ pushdecl_maybe_friend_1 (tree x, bool is_friend)
&& in_function_try_handler)) && in_function_try_handler))
{ {
if (permerror (input_location, "redeclaration of %q#D", x)) if (permerror (input_location, "redeclaration of %q#D", x))
inform (input_location, "%q+#D previously declared here", inform (DECL_SOURCE_LOCATION (oldlocal),
oldlocal); "%q#D previously declared here", oldlocal);
nowarn = true; nowarn = true;
} }
...@@ -1410,9 +1411,11 @@ check_for_out_of_scope_variable (tree decl) ...@@ -1410,9 +1411,11 @@ check_for_out_of_scope_variable (tree decl)
if (!DECL_ERROR_REPORTED (decl)) if (!DECL_ERROR_REPORTED (decl))
{ {
warning (0, "name lookup of %qD changed", DECL_NAME (decl)); warning (0, "name lookup of %qD changed", DECL_NAME (decl));
warning (0, " matches this %q+D under ISO standard rules", warning_at (DECL_SOURCE_LOCATION (shadowed), 0,
" matches this %qD under ISO standard rules",
shadowed); shadowed);
warning (0, " matches this %q+D under old rules", decl); warning_at (DECL_SOURCE_LOCATION (decl), 0,
" matches this %qD under old rules", decl);
DECL_ERROR_REPORTED (decl) = 1; DECL_ERROR_REPORTED (decl) = 1;
} }
return shadowed; return shadowed;
...@@ -1441,7 +1444,8 @@ check_for_out_of_scope_variable (tree decl) ...@@ -1441,7 +1444,8 @@ check_for_out_of_scope_variable (tree decl)
permerror (input_location, "name lookup of %qD changed for ISO %<for%> scoping", permerror (input_location, "name lookup of %qD changed for ISO %<for%> scoping",
DECL_NAME (decl)); DECL_NAME (decl));
if (flag_permissive) if (flag_permissive)
permerror (input_location, " using obsolete binding at %q+D", decl); permerror (DECL_SOURCE_LOCATION (decl),
" using obsolete binding at %qD", decl);
else else
{ {
static bool hint; static bool hint;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment