C++ Logo

STD-DISCUSSION

Advanced search

Subject: Re: Aggregate initialization with reuse?
From: Ville Voutilainen (ville.voutilainen_at_[hidden])
Date: 2019-06-02 10:09:34


On Sun, 2 Jun 2019 at 17:34, Language Lawyer via Std-Discussion
<std-discussion_at_[hidden]> wrote:
>
> https://stackoverflow.com/a/32945791/9585016

In other words,

1) a is in scope per http://eel.is/c++draft/basic.scope.pdecl#1
2) a.x has been completely initialized per
http://eel.is/c++draft/dcl.init.aggr#6

The initialization is well-formed, legal, and does what you expect.
The earlier statements about designated initializers
do not apply, but if we choose to modify the example to use designated
initializers, it still works:

struct {
  int x;
  int y;
} a{.x = 42, .y = a.x};


STD-DISCUSSION list run by herb.sutter at gmail.com

Older Archives on Google Groups