This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] PR c++/80544 strip cv-quals from cast results
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Jonathan Wakely <jwakely at redhat dot com>
- Cc: Andreas Schwab <schwab at linux-m68k dot org>, Jason Merrill <jason at redhat dot com>, gcc-patches List <gcc-patches at gcc dot gnu dot org>, Nathan Sidwell <nathan at acm dot org>
- Date: Thu, 25 May 2017 16:14:07 +0200
- Subject: Re: [PATCH] PR c++/80544 strip cv-quals from cast results
- Authentication-results: sourceware.org; auth=none
- Authentication-results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com
- Authentication-results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jakub at redhat dot com
- Dkim-filter: OpenDKIM Filter v2.11.0 mx1.redhat.com B8F497F6CE
- Dmarc-filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B8F497F6CE
- References: <20170427165907.GL5109@redhat.com> <CADzB+2nMhFnDrqk1jbE3nDx7b1hukJuWB3J5pSt=dGXmceOVPA@mail.gmail.com> <20170523180046.GG12306@redhat.com> <CADzB+2=yocABQpVueGU4rTwLbTwn1f8wkT2FEUC4ZS0=Ai+oig@mail.gmail.com> <20170524142022.GJ12306@redhat.com> <m2inkp744p.fsf@linux-m68k.org> <20170525100700.GU12306@redhat.com> <20170525140242.GA12306@redhat.com> <20170525141119.GE8499@tucnak>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Thu, May 25, 2017 at 04:11:19PM +0200, Jakub Jelinek wrote:
> So, what can one do with typeof or similar to avoid the warning?
>
> void
> foo (const void *p)
> {
> const int *const q = (const int *const) p;
> typeof (q) r = (typeof (q)) p;
> (void) q;
> (void) r;
> }
>
> AFAIK typeof doesn't strip the toplevel qualifiers and I see current trunk
> warns even about the cast in r initialization. Similarly to what has been
> noted recently in another (C) PR, it would be nice if we had toplevel cv
> stripping variant of typeof or some special builtin that could wrap
> typeof or some type and could be used in places where typeof can,
> __strip_cv (typeof (q)) = (__strip_cv (typeof (q))) p;
> or
> typeof (q) = (__strip_cv (typeof (q))) p;
> or
> __strip_cv (const int *const) z;
> where the last one would be effectively
> const int *z;
I guess in C++ one can use
typeof (q) r = (remove_cv <typeof (q)>::type) p;
or something similar, but in C there is nothing like that.
Jakub