[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gcc-patches
Subject:    Re: [PATCH] c++: Fixing the wording of () aggregate-init [PR92812]
From:       Marek Polacek via Gcc-patches <gcc-patches () gcc ! gnu ! org>
Date:       2020-07-31 17:24:34
Message-ID: 20200731172434.GB1314761 () redhat ! com
[Download RAW message or body]

On Wed, Jul 29, 2020 at 07:21:46PM -0400, Jason Merrill via Gcc-patches wrote:
> On 7/20/20 7:28 PM, Marek Polacek wrote:
> > P1975R0 tweaks the static_cast wording: it says that "An expression e can be
> > explicitly converted to a type T if [...] T is an aggregate type having a first
> > element x and there is an implicit conversion sequence from e to the type of
> > x."  This already works for classes, e.g.:
> > 
> >    struct Aggr { int x; int y; };
> >    Aggr a = static_cast<Aggr>(1);
> > 
> > albeit I noticed a -Wmissing-field-initializer warning which is unlikely to be
> > helpful in this context, as there's nothing like static_cast<Aggr>(1, 2)
> > to quash that warning.
> 
> You could write Aggr{1,2} instead?
> 
> This warning could be helpful if they didn't realize that what they were
> writing is initializing one element of an aggregate.

Ok, I can drop it.  Though explicit cast usually suppress warnings like that.

> > However, the proposal also mentions "If T is ``array of unknown bound of U'',
> > this direct-initialization defines the type of the expression as U[1]" which
> > suggest that this should work for arrays (they're aggregates too, after all).
> > Ville, can you confirm that these
> > 
> >    int (&&r)[3] = static_cast<int[3]>(42);
> >    int (&&r2)[1] = static_cast<int[]>(42);
> > 
> > are supposed to work now?  There's no {} variant to check.  Thanks.
> 
> I'll review the discussion of this later.

It's become clear that the array cases are supposed to work, so I think
let's drop this patch and I'll post a new patch when I get the array cases
working.

Thanks,
Marek

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic