This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: C/C++ PATCH to add __typeof_noqual (PR c/65455, c/39985)
- From: Marek Polacek <polacek at redhat dot com>
- To: Martin Sebor <msebor at gmail dot com>
- Cc: Joseph Myers <joseph at codesourcery dot com>, GCC Patches <gcc-patches at gcc dot gnu dot org>, Jason Merrill <jason at redhat dot com>
- Date: Wed, 19 Jul 2017 13:29:06 +0200
- Subject: Re: C/C++ PATCH to add __typeof_noqual (PR c/65455, c/39985)
- Authentication-results: sourceware.org; auth=none
- Authentication-results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com
- Authentication-results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=polacek at redhat dot com
- Dkim-filter: OpenDKIM Filter v2.11.0 mx1.redhat.com E393E2F86DA
- Dmarc-filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E393E2F86DA
- References: <alpine.DEB.2.20.1706272220180.21267@digraph.polyomino.org.uk> <1321c7ba-5cd1-2958-4c9b-ebd54401846a@gmail.com> <alpine.DEB.2.20.1706280912080.6445@digraph.polyomino.org.uk> <aa22353f-bb8e-a655-b80c-76f58b59a23c@gmail.com> <alpine.DEB.2.20.1706281606430.25698@digraph.polyomino.org.uk> <2ad85380-f70a-195f-f968-e46c9f24fa8a@gmail.com> <alpine.DEB.2.20.1706281740420.25698@digraph.polyomino.org.uk> <53f40270-74e6-8ef7-65dd-447e16023bb5@gmail.com> <alpine.DEB.2.20.1706291554320.7727@digraph.polyomino.org.uk> <472ad1ea-eda5-f3d9-5f7f-be09c733a154@gmail.com>
On Thu, Jun 29, 2017 at 10:35:26AM -0600, Martin Sebor wrote:
> On 06/29/2017 09:56 AM, Joseph Myers wrote:
> > On Wed, 28 Jun 2017, Martin Sebor wrote:
> >
> > > > The more limited interfaces could, of course, be __typeof_noqual in some
> > > > form.
> > >
> > > Actually, despite what I've been arguing, I agree. I've come
> > > to realize that what makes me uneasy about it is its name: it
> > > makes it sound like a special purpose flavor of __typeof__,
> > > when it really is a general purpose __remove_qualifiers trait.
> > > How does renaming it to something like that sound?
> >
> > __typeof__ makes clear that it returns a type, whether given a type or an
> > expression. Can __remove_qualifiers be applied to an expression, and, if
> > so, what does it do - return a type, or return the result of converting
> > the expression to the corresponding type with whatever qualifiers removed?
Sorry it's taken so long to respond.
> The C++ traits primitives
> (https://gcc.gnu.org/onlinedocs/gcc/Type-Traits.html) work on types,
> not expressions, so I would suggest to have __remove_qualifiers (and
> the related __remove_const et al., if they should be added) follow
> the same approach.
OK, let's say __remove_qualifiers only works for type names. So then to
accomodate PR65455 and others we'd suggest
const int a = 3;
__remove_qualifiers (__typeof__(a)) x;
?
If that's the case, then I'll write a patch that does just that.
Regarding __remove_qualifiers (types, expr) and__remove_qualifiers_except,
I'd rather not pursue as part of this patch.
> PS There are at least a couple of traits on the list above that
> would be useful in C as well (__is_enum and __is_union, and maybe
> also __underlying_type).
This could be fun, but what's the use case for C? Generic programming?
Not familiar with that; would certainly appreciate some test cases before
I dive into that.
Marek