c-typeck.c (build_c_cast): Warn when qualifiers are added to function types, not when they're taken away.

* c-typeck.c (build_c_cast): Warn when qualifiers are added to
	function types, not when they're taken away.

From-SVN: r49481
This commit is contained in:
Richard Sandiford 2002-02-04 17:01:30 +00:00 committed by Richard Sandiford
parent e89a607588
commit af702de897
2 changed files with 21 additions and 3 deletions

View File

@ -1,3 +1,8 @@
2002-02-04 Richard Sandiford <rsandifo@redhat.com>
* c-typeck.c (build_c_cast): Warn when qualifiers are added to
function types, not when they're taken away.
Mon Feb 4 09:05:58 2002 Jeffrey A Law (law@redhat.com)
* cfgrtl.c (try_redirect_by_replacing_jump): Remove associated

View File

@ -3819,7 +3819,8 @@ build_c_cast (type, expr)
{
tree in_type = type;
tree in_otype = otype;
int warn = 0;
int added = 0;
int discarded = 0;
/* Check that the qualifiers on IN_TYPE are a superset of
the qualifiers of IN_OTYPE. The outermost level of
@ -3829,12 +3830,24 @@ build_c_cast (type, expr)
{
in_otype = TREE_TYPE (in_otype);
in_type = TREE_TYPE (in_type);
warn |= (TYPE_QUALS (in_otype) & ~TYPE_QUALS (in_type));
/* GNU C allows cv-qualified function types. 'const'
means the function is very pure, 'volatile' means it
can't return. We need to warn when such qualifiers
are added, not when they're taken away. */
if (TREE_CODE (in_otype) == FUNCTION_TYPE
&& TREE_CODE (in_type) == FUNCTION_TYPE)
added |= (TYPE_QUALS (in_type) & ~TYPE_QUALS (in_otype));
else
discarded |= (TYPE_QUALS (in_otype) & ~TYPE_QUALS (in_type));
}
while (TREE_CODE (in_type) == POINTER_TYPE
&& TREE_CODE (in_otype) == POINTER_TYPE);
if (warn)
if (added)
warning ("cast adds new qualifiers to function type");
if (discarded)
/* There are qualifiers present in IN_OTYPE that are not
present in IN_TYPE. */
warning ("cast discards qualifiers from pointer target type");