aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Sandiford <rsandifo@redhat.com>2002-02-04 17:01:30 +0000
committerRichard Sandiford <rsandifo@gcc.gnu.org>2002-02-04 17:01:30 +0000
commitaf702de897e40d55efee12aafd7a9d797c52d49c (patch)
tree869f58d3da9166346a73429164908e4bd2f2cbd0
parente89a607588d6a34db572bb0277d65ec8334500ce (diff)
downloadgcc-af702de897e40d55efee12aafd7a9d797c52d49c.zip
gcc-af702de897e40d55efee12aafd7a9d797c52d49c.tar.gz
gcc-af702de897e40d55efee12aafd7a9d797c52d49c.tar.bz2
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
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/c-typeck.c19
2 files changed, 21 insertions, 3 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 63c0ce5..102e0ab 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -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
diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c
index 37f6a87..a00c724 100644
--- a/gcc/c-typeck.c
+++ b/gcc/c-typeck.c
@@ -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");