From patchwork Wed Jun 9 12:11:59 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?TWFudWVsIEzDs3Blei1JYsOhw7Fleg==?= X-Patchwork-Id: 55086 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id C4DBE1007D2 for ; Wed, 9 Jun 2010 22:17:58 +1000 (EST) Received: (qmail 21088 invoked by alias); 9 Jun 2010 12:17:54 -0000 Received: (qmail 21060 invoked by uid 22791); 9 Jun 2010 12:17:49 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM X-Spam-Check-By: sourceware.org Received: from mail-wy0-f175.google.com (HELO mail-wy0-f175.google.com) (74.125.82.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 09 Jun 2010 12:17:44 +0000 Received: by wyi11 with SMTP id 11so176444wyi.20 for ; Wed, 09 Jun 2010 05:17:41 -0700 (PDT) Received: by 10.227.142.69 with SMTP id p5mr1640150wbu.2.1276085542967; Wed, 09 Jun 2010 05:12:22 -0700 (PDT) MIME-Version: 1.0 Received: by 10.216.21.6 with HTTP; Wed, 9 Jun 2010 05:11:59 -0700 (PDT) In-Reply-To: References: <20100607005213.GQ19235@codesourcery.com> <4C0E4E60.6010905@redhat.com> <4C0E6C5C.1060003@redhat.com> From: =?ISO-8859-1?Q?Manuel_L=F3pez=2DIb=E1=F1ez?= Date: Wed, 9 Jun 2010 14:11:59 +0200 Message-ID: Subject: Re: [PATCH,c++] use XALLOCAVEC in the C++ front-end To: Gabriel Dos Reis Cc: Jason Merrill , Nathan Froyd , gcc-patches@gcc.gnu.org, "Joseph S. Myers" X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org On 9 June 2010 14:08, Gabriel Dos Reis wrote: > On Wed, Jun 9, 2010 at 6:53 AM, Manuel López-Ibáñez > wrote: >> On 9 June 2010 13:33, Gabriel Dos Reis wrote: >>> On Wed, Jun 9, 2010 at 4:53 AM, Manuel López-Ibáñez >>> wrote: >>>> On 8 June 2010 18:14, Jason Merrill wrote: >>>>> On 06/08/2010 10:43 AM, Manuel López-Ibáñez wrote: >>>>>> >>>>>> On 8 June 2010 16:06, Jason Merrill  wrote: >>>>> >>>>>>> The error message is unclear, but the issue is that converting from >>>>>>> char** >>>>>>> to char const** is unsafe, while converting to char const*const* is safe. >>>>>> >>>>>> What does it mean unsafe in this context? I could produce a patch that >>>>>> changes the message but I would like to be sure what to say. >>>>>> >>>>>> semantics.c:1223:7: error: new ‘const’ qualifier in cast from 'char >>>>>> **' to 'const char **' is unsafe [-Werror=cast-qual] >>>>> Explanation from the C++ standard (4.4 [conv.qual]): >>>>> >>>>> [ Note: if a program could assign a pointer of type T** to a pointer of type >>>>> const T** (that is, if line #1 below were allowed), a program could >>>>> inadvertently modify a const object (as it is done on line #2). For example, >>>>> >>>>>  int main() { >>>>>    const char c = ’c’; >>>>>    char* pc; >>>>>    const char** pcc = &pc;// #1: not allowed >>>>>    *pcc = &c; >>>>>    *pc = ’C’; // #2: modifies a const object >>>>>  } >>>>> --end note ] >>>> >>>> So what do you think about the following message: >>>> >>>> error: new ‘const’ qualifier in cast from 'char **' to 'const char **' >>>> is unsafe [-Werror=cast-qual] >>>> note: to be safe all intermediate pointers must be equally qualified >>> >>> that is OK; but I find the leading 'new' hard to parse.   Please, just >>> remove it. >>> >> >> Anyway, this is the C FE. > > Yes, I know. > >> The C++ FE gives the following: >> >> test.C:4:23: warning: invalid conversion from ‘char**’ to ‘const >> char**’ [-fpermissive] >> >> but the code is too intricate to give a clearer error in the case of >> C++ or to factor out the common check. > > Removing the leading 'new' does not require any of that. Of course, it was a just a comment since consistency between C and C++ is a goal, so we should always check for low hanging-fruit. Not this case unfortunately. I am bootstrapping this: There will be some testcases that need adjusting. Cheers, Manuel. Index: gcc/c-typeck.c =================================================================== --- gcc/c-typeck.c (revision 160384) +++ gcc/c-typeck.c (working copy) @@ -4493,9 +4493,12 @@ && !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); + if (warning_at (input_location, OPT_Wcast_qual, + "%qv qualifier in cast from %qT to %qT is unsafe", + added, in_type, in_otype)) + inform (input_location, + G_("to be safe all intermediate pointers" + " must be equally qualified")); break; } if (is_const)