===================================================================
@@ -4411,16 +4411,17 @@ build_compound_expr (location_t loc, tre
return ret;
}
/* Issue -Wcast-qual warnings when appropriate. TYPE is the type to
which we are casting. OTYPE is the type of the expression being
- cast. Both TYPE and OTYPE are pointer types. -Wcast-qual appeared
- on the command line. Named address space qualifiers are not handled
- here, because they result in different warnings. */
+ cast. Both TYPE and OTYPE are pointer types. LOC is the location
+ of the cast. -Wcast-qual appeared on the command line. Named
+ address space qualifiers are not handled here, because they result
+ in different warnings. */
static void
-handle_warn_cast_qual (tree type, tree otype)
+handle_warn_cast_qual (location_t loc, tree type, tree otype)
{
tree in_type = type;
tree in_otype = otype;
int added = 0;
int discarded = 0;
@@ -4449,19 +4450,19 @@ handle_warn_cast_qual (tree type, tree o
}
while (TREE_CODE (in_type) == POINTER_TYPE
&& TREE_CODE (in_otype) == POINTER_TYPE);
if (added)
- warning (OPT_Wcast_qual, "cast adds %q#v qualifier to function type",
- added);
+ warning_at (loc, OPT_Wcast_qual,
+ "cast adds %q#v qualifier to function type", added);
if (discarded)
/* There are qualifiers present in IN_OTYPE that are not present
in IN_TYPE. */
- warning (OPT_Wcast_qual,
- "cast discards %q#v qualifier from pointer target type",
- discarded);
+ warning_at (loc, OPT_Wcast_qual,
+ "cast discards %q#v qualifier from pointer target type",
+ discarded);
if (added || discarded)
return;
/* A cast from **T to const **T is unsafe, because it can cause a
@@ -4490,14 +4491,14 @@ handle_warn_cast_qual (tree type, tree o
in_type = TREE_TYPE (in_type);
in_otype = TREE_TYPE (in_otype);
if ((TYPE_QUALS (in_type) &~ TYPE_QUALS (in_otype)) != 0
&& !is_const)
{
- int added = TYPE_QUALS (in_type) &~ TYPE_QUALS (in_otype);
- warning (OPT_Wcast_qual,
- ("new %qv qualifier in middle of multi-level non-const cast "
- "is unsafe"), added);
+ warning_at (loc, OPT_Wcast_qual,
+ G_("to be safe all intermediate pointers in cast from "
+ "%qT to %qT must be %<const%> qualified"),
+ otype, type);
break;
}
if (is_const)
is_const = TYPE_READONLY (in_type);
}
@@ -4597,11 +4598,11 @@ build_c_cast (location_t loc, tree type,
/* Optionally warn about potentially worrisome casts. */
if (warn_cast_qual
&& TREE_CODE (type) == POINTER_TYPE
&& TREE_CODE (otype) == POINTER_TYPE)
- handle_warn_cast_qual (type, otype);
+ handle_warn_cast_qual (loc, type, otype);
/* Warn about conversions between pointers to disjoint
address spaces. */
if (TREE_CODE (type) == POINTER_TYPE
&& TREE_CODE (otype) == POINTER_TYPE