c-typeck.c (handle_warn_cast_qual): Add loc parameter.
authorManuel López-Ibáñez <manu@gcc.gnu.org>
Fri, 11 Jun 2010 09:43:53 +0000 (09:43 +0000)
committerManuel López-Ibáñez <manu@gcc.gnu.org>
Fri, 11 Jun 2010 09:43:53 +0000 (09:43 +0000)
2010-06-11  Manuel López-Ibáñez  <manu@gcc.gnu.org>

* c-typeck.c (handle_warn_cast_qual): Add loc
parameter. Improve warning message.
(build_c_cast): Pass location to handle_warn_cast_qual.

From-SVN: r160601

gcc/ChangeLog
gcc/c-typeck.c

index 561b0eed0f961b7a30d0b9419029af4eb10c6ef8..742950c041bb8045ab683dc7b4c021645d4d0877 100644 (file)
@@ -1,3 +1,9 @@
+2010-06-11  Manuel López-Ibáñez  <manu@gcc.gnu.org>
+
+       * c-typeck.c (handle_warn_cast_qual): Add loc
+       parameter. Improve warning message.
+       (build_c_cast): Pass location to handle_warn_cast_qual.
+
 2010-06-11  Uros Bizjak  <ubizjak@gmail.com>
 
        * config/i386/i386.md (pro_epilogue_adjust_stack_1) <TYPE_ALU>: Assert
index b2d3986e185f9579b166809587244e43d1fa812f..f8bfb51971180a4c80b7690971c39cef4df7327f 100644 (file)
@@ -4413,12 +4413,13 @@ build_compound_expr (location_t loc, tree expr1, tree expr2)
 
 /* 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;
@@ -4451,15 +4452,15 @@ handle_warn_cast_qual (tree type, tree otype)
         && 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;
@@ -4492,10 +4493,10 @@ handle_warn_cast_qual (tree type, tree 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,
+                     "to be safe all intermediate pointers in cast from "
+                      "%qT to %qT must be %<const%> qualified",
+                     otype, type);
          break;
        }
       if (is_const)
@@ -4599,7 +4600,7 @@ build_c_cast (location_t loc, tree type, tree expr)
       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.  */