c-typeck.c (build_c_cast): Warn when qualifiers are added to function types, not...
authorRichard Sandiford <rsandifo@redhat.com>
Mon, 4 Feb 2002 17:01:30 +0000 (17:01 +0000)
committerRichard Sandiford <rsandifo@gcc.gnu.org>
Mon, 4 Feb 2002 17:01:30 +0000 (17:01 +0000)
* c-typeck.c (build_c_cast): Warn when qualifiers are added to
function types, not when they're taken away.

From-SVN: r49481

gcc/ChangeLog
gcc/c-typeck.c

index 63c0ce5302636a96674c12ba495e49bbb269c641..102e0abf8ebb0b232cc4a8002f2f6dc430f63992 100644 (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
index 37f6a8779e59beb18053cea7ef5d3d4a28781082..a00c7241f7e0fc0f6873f408781f6c4a288782a4 100644 (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");