From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18922 invoked by alias); 6 Aug 2007 04:42:25 -0000 Received: (qmail 18243 invoked by uid 22791); 6 Aug 2007 04:42:22 -0000 X-Spam-Check-By: sourceware.org Received: from caip.rutgers.edu (HELO caip.rutgers.edu) (128.6.236.16) by sourceware.org (qpsmtpd/0.31) with ESMTP; Mon, 06 Aug 2007 04:42:17 +0000 Received: from caipclassic.rutgers.edu (caipclassic.rutgers.edu [128.6.237.54]) by caip.rutgers.edu (8.13.8/8.13.5) with ESMTP id l764cAAN000516 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 6 Aug 2007 00:38:11 -0400 Date: Mon, 06 Aug 2007 04:42:00 -0000 From: "Kaveh R. GHAZI" To: Gabriel Dos Reis cc: Mark Mitchell , Richard Guenther , gcc-patches@gcc.gnu.org Subject: Re: [PATCH]: Fix problematic -Wcast-qual cases using new CONST_CAST macro In-Reply-To: Message-ID: References: <84fc9c000707270219i4702de61y70899cd7e3349d72@mail.gmail.com> <84fc9c000707271138u6171f592x3f69800f12106a0a@mail.gmail.com> <87odhozdvp.fsf@soliton.cs.tamu.edu> <46B668EB.6080708@codesourcery.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2007-08/txt/msg00304.txt.bz2 On Sun, 5 Aug 2007, Gabriel Dos Reis wrote: > On Sun, 5 Aug 2007, Mark Mitchell wrote: > > | Gabriel Dos Reis wrote: > | > | > | Richard, do you have any remaining objections to this patch? > | > | http://gcc.gnu.org/ml/gcc-patches/2007-07/msg01993.html > | > | I'm not very keen on the use of a union here, just as a way to outwit > | our own warning machinery. > > A good point that the union is overkill. I used a union because it's the only solution I found that works. I would be happy to use something else more elegant if someone suggests something concrete. > | For grep-ability, just using CONST_CAST with > | a definition that is a traditional C-style cast, would work fine. > > The compiler will "see" through the macro expansion and will start > warning when -Wcast-qual is on. Right. > | Or, > | can we go through an inline function, with warnings disabled on the > | inline function? How do we disable warnings on the fly inside an inline function? Did someone implement "#pragma nowarn foo" when I wasn't looking? > I don't know whether this works; Kaveh can you try it? > (You would still have to write the function name all caps). > -- Gaby Sure, but try what exactly? I attempted various inline function permutations and the only thing that works is putting a union inside the inline function. (By "works" I mean silences -Wcast-qual warning.) I don't see how putting the union inside an inline function as any better than using a macro, in fact the inline function version is slightly worse. It can't use __typeof() like Richard suggested because the function prototype hides the arguments actual type. In light of this, I'd like permission to install my existing patch. If someone can suggest a better definition for CONST_CAST() and/or write an inline function to replace it, it's merely a one-line change to system.h as a follow-up. Until then, the union hack is the only thing I can think of that actually does the job. Okay? Thanks, --Kaveh -- Kaveh R. Ghazi ghazi@caip.rutgers.edu