diff mbox

[c++] use XALLOCAVEC in the C++ front-end

Message ID AANLkTim9ZYKlKDLa8FcH0CisNy5YEM3fEiwQyZtDWjWS@mail.gmail.com
State New
Headers show

Commit Message

Manuel López-Ibáñez June 10, 2010, 11:45 p.m. UTC
On 9 June 2010 22:35, Joseph S. Myers <joseph@codesourcery.com> wrote:
> On Wed, 9 Jun 2010, Manuel López-Ibáñez wrote:
>
>> note: to be safe all intermediate pointers must be equally qualified
>
> The requirement is not that they be equally qualified, it's that they be
> const-qualified.  (That is, if you are adding "volatile" qualifiers,
> "const" is still needed at intermediate levels; you can convert char ** to
> volatile char *const * but not to volatile char *volatile *.)

Bootstrapped and regression tested on x86_64-linux-gnu. OK for trunk?

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.

Comments

Manuel López-Ibáñez June 11, 2010, 9:44 a.m. UTC | #1
On 11 June 2010 11:33, Joseph S. Myers <joseph@codesourcery.com> wrote:
> On Fri, 11 Jun 2010, Manuel López-Ibáñez wrote:
>
>> On 9 June 2010 22:35, Joseph S. Myers <joseph@codesourcery.com> wrote:
>> > On Wed, 9 Jun 2010, Manuel López-Ibáñez wrote:
>> >
>> >> note: to be safe all intermediate pointers must be equally qualified
>> >
>> > The requirement is not that they be equally qualified, it's that they be
>> > const-qualified.  (That is, if you are adding "volatile" qualifiers,
>> > "const" is still needed at intermediate levels; you can convert char ** to
>> > volatile char *const * but not to volatile char *volatile *.)
>>
>> Bootstrapped and regression tested on x86_64-linux-gnu. OK for trunk?
>>
>> 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.
>
> Remove the explicit G_(), which isn't needed in a call to warning_at.  OK
> with that change.

Committed revision 160601.
diff mbox

Patch

Index: gcc/c-typeck.c
===================================================================
--- gcc/c-typeck.c	(revision 160464)
+++ gcc/c-typeck.c	(working copy)
@@ -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