From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10094 invoked by alias); 21 May 2009 10:21:02 -0000 Received: (qmail 10076 invoked by uid 22791); 21 May 2009 10:21:01 -0000 X-SWARE-Spam-Status: No, hits=-1.1 required=5.0 tests=AWL,BAYES_05,SARE_MSGID_LONG40,SPF_PASS,WEIRD_PORT X-Spam-Check-By: sourceware.org Received: from qw-out-1920.google.com (HELO qw-out-1920.google.com) (74.125.92.149) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 21 May 2009 10:20:56 +0000 Received: by qw-out-1920.google.com with SMTP id 4so667686qwk.14 for ; Thu, 21 May 2009 03:20:54 -0700 (PDT) MIME-Version: 1.0 Received: by 10.220.73.69 with SMTP id p5mr2553902vcj.11.1242901253956; Thu, 21 May 2009 03:20:53 -0700 (PDT) In-Reply-To: References: Date: Thu, 21 May 2009 11:58:00 -0000 Message-ID: <84fc9c000905210320g7525cb8cob268133e82896ec1@mail.gmail.com> Subject: Re: -Wcast-qual and casting away From: Richard Guenther To: Ian Lance Taylor Cc: gcc@gcc.gnu.org Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org X-SW-Source: 2009-05/txt/msg00540.txt.bz2 On Thu, May 21, 2009 at 7:10 AM, Ian Lance Taylor wrote: > Consider this C/C++ program: > > extern void **f1(); > void f2(const char *p) { *(const void **)f1() =3D p; } > > If I compile this program with g++ -Wcast-qual, I get this: > > foo2.cc:2: warning: cast from type =91void**=92 to type =91const void**= =92 casts away qualifiers > > If I compile this program with gcc -Wcast-qual, I do not get any > warning. > > Let's overlook the fact that the text of the g++ warning does not make > any sense--I am certainly not casting anything away. =A0The warning is > conceptually plausible for the same reason that you can't assign a > char** variable to a const char** variable without a cast. =A0At least, I > think one could make a argument that that is so. =A0But it's not a *very* > strong argument, as -Wcast-qual is documented to warn about cases where > a type qualifier is removed, and that is manifestly not happening here. > -Wcast-qual is useful to catch certain programming errors; I don't think > anybody adding a const qualifier is actually making a mistake. > > All that aside, I can't think of any reason that the C and C++ frontends > should be different in this regard. =A0Does anybody want to make an > argument for which of these choices we should adopt? > > 1) Keep things the same: the C++ frontend warns, the C frontend doesn't. > =A0 Consistency is overrated. > > 2) Change the C frontend to also warn about this case, albeit with a > =A0 better message. > > 3) Change the C++ frontend to not warn about this case. > > Of course in all cases the frontends should continue to warn about a > cast from const void** to void**. As the C++ warning doesn't make any sense I vote for 3). Richard. > Ian >