public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Marek Polacek <polacek@redhat.com>
To: Ville Voutilainen <ville.voutilainen@gmail.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>, Jason Merrill <jason@redhat.com>
Subject: Re: [PATCH] c++: Fixing the wording of () aggregate-init [PR92812]
Date: Tue, 21 Jul 2020 14:56:53 -0400	[thread overview]
Message-ID: <20200721185653.GH3841@redhat.com> (raw)
In-Reply-To: <CAFk2RUY48rCF=eygRN5FywWjgNg_VX=WhfHOs_BYTfGR_PS=Jw@mail.gmail.com>

On Tue, Jul 21, 2020 at 12:53:03PM +0300, Ville Voutilainen wrote:
> On Tue, 21 Jul 2020 at 02:28, Marek Polacek <polacek@redhat.com> 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.
> >
> > 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 don't know what it means to cast something to an array; doesn't that create
> an array prvalue? Is that a thing?

Yes, I imagined this would be similar to

using T = int[3];
int (&&r)[3] = T{1, 2, 3}; // binds to array prvalue, lifetime extended

but I'd like to avoid allowing code that isn't supposed to work.
We also might want to consider if we want to extend the lifetime of r/r2 in my
previous example (I think so; DRs 1299/1376).  Worth bothering CWG?

Marek


  reply	other threads:[~2020-07-21 18:56 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-20 23:28 Marek Polacek
2020-07-21  9:53 ` Ville Voutilainen
2020-07-21 18:56   ` Marek Polacek [this message]
2020-07-21 19:03     ` Ville Voutilainen
2020-07-21 19:38       ` Marek Polacek
2020-07-21 19:52         ` Ville Voutilainen
2020-07-29 23:21 ` Jason Merrill
2020-07-31 17:24   ` Marek Polacek
2020-08-11 23:34 Marek Polacek
2020-08-12 20:10 ` Jason Merrill

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200721185653.GH3841@redhat.com \
    --to=polacek@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jason@redhat.com \
    --cc=ville.voutilainen@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).