Skip to content

Commit 06e7191

Browse files
committed
[P2287] CWG updates
1 parent 717ab8c commit 06e7191

File tree

2 files changed

+31
-16
lines changed

2 files changed

+31
-16
lines changed

2287_designated_base/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
p2287r3.html : designated-base.md
1+
d2287r4.html : designated-base.md
22
include ../md/mpark-wg21.mk

2287_designated_base/designated-base.md

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
22
title: "Designated-initializers for Base Classes"
3-
document: P2287R3
3+
document: D2287R4
44
date: today
5-
audience: EWG
5+
audience: CWG
66
author:
77
- name: Barry Revzin
88
email: <barry.revzin@gmail.com>
@@ -122,13 +122,13 @@ auto b = B{.a=1, .b=2};
122122
```
123123
:::
124124
125-
And in a type that has a base class that is not an aggregate, you can use the mix-and-match form:
125+
And in a type that has a base class that is not an aggregate, you can use the mix-and-match form if you use braces:
126126
127127
::: std
128128
```cpp
129129
struct C : std::string { int c; };
130130
131-
auto c1 = C{"hello", .c=3};
131+
auto c1 = C{"hello", .c=3}; // ill-formed
132132
auto c2 = C{{"hello"}, .c=3};
133133
```
134134
:::
@@ -142,7 +142,7 @@ struct E : D { int x; };
142142

143143
auto e1 = E{.x=1}; // initializes E::x, not D::x
144144
auto e2 = E{{.x=1}, .x=2}; // initializes D::x to 1 and E::x to 2
145-
auto e3 = E{D{1}, .x=2}; // likewise
145+
auto e3 = E{D{1}, .x=2}; // ill-formed
146146
```
147147
:::
148148
@@ -271,9 +271,13 @@ Change the grammar in [dcl.init.general]{.sref}/1 to allow a `$designated-initia
271271
272272
::: std
273273
```diff
274+
+ $braced-init-list-list$:
275+
+ $braced-init-list$
276+
+ $braced-init-list$ , $braced-init-list-list$
277+
274278
$designated-initializer-list$:
275279
+ $designated-only-initializer-list$
276-
+ $initializer-list$ , $designated-only-initializer-list$
280+
+ $braced-init-list-list$ , $designated-only-initializer-list$
277281
278282
+ $designated-only-initializer-list$:
279283
$designated-initializer-clause$
@@ -288,38 +292,49 @@ Add a new term after we define what an aggregate and the elements of an aggregat
288292
::: addu
289293
[*]{.pnum} The _designatable members_ of an aggregate `T` are:
290294

291-
* [*.1]{.pnum} For each direct base class `C` of `T` that is an aggregate class, the designatable members of `C` for which lookup for that member in `T` finds the member of `C`,
292-
* [*.2]{.pnum} The ordered *identifiers* in the direct non-static members of `T`.
295+
* [*.1]{.pnum} For each direct base class `C` of `T` that is an aggregate class, in order they appear in the `$base-specifier-list$`, the designatable members of `C` for which lookup for that member in `T` finds the member of `C`, followed by
296+
* [*.2]{.pnum} the direct non-static data members of `T`, in declaration order.
293297
:::
294298
:::
295299

296300
Extend [dcl.init.aggr]{.sref}/3.1:
297301

298302
::: std
299-
[3.1]{.pnum} If the initializer list is a brace-enclosed *designated-initializer-list*, the aggregate shall be of class type[, the identifier in each designator shall name a direct non-static data member of the class, and the explicitly initialized elements of the aggregate are the elements that are, or contain, those members.]{.rm} [`C` .]{.addu}
303+
[3.1]{.pnum} If the initializer list is a brace-enclosed `$designated-initializer-list$`, the aggregate shall be of class type[, the identifier in each designator shall name a direct non-static data member of the class, and the explicitly initialized elements of the aggregate are the elements that are, or contain, those members.]{.rm} [`C`.]{.addu}
304+
305+
::: addu
306+
The explicitly initialized elements of `$C$` are:
307+
308+
* [3.1.1]{.pnum} For each `$braced-init-list$` in the `$designated-initializer-list$`, the base class subobject of `$C$` which the `$braced-init-list$` appertains to (see below), and
309+
* [3.1.2]{.pnum} for each `$identifier$` in the `$designated-initializer-list$`, the designatable member of `$C$` named by, or containing (in the case of an anonymous union or a base class), that `$identifier$`.
310+
:::
311+
312+
In either case, if there is either no such base class subobject or no such designatable member, the program is ill-formed.
313+
314+
old wording here:
300315

301316
::: addu
302-
* [3.1.1]{.pnum} If the initializer list contains a `$initializer-list$`, then each `$initializer-clause$` in the `$initializer-list$` shall appertain (see below) to a base class subobject of `C` and the `$identifier$` in each `$designator$` shall name a direct non-static data member of `C`, and the explicitly initialized elements of the aggregate are those base class subobjects and direct members.
317+
* [3.1.1]{.pnum} Each `$braced-init-list$` in the `$designated-initializer-list$` shall appertain (see below) to a base class subobject of `C` and the `$identifier$` in each `$designator$` shall name a direct non-static data member of `C`. The explicitly initialized elements of the aggregate are those base class subobjects and direct members.
303318
* [3.1.2]{.pnum} Otherwise, the `$identifier$` in each `$designator$` shall name a designatable member of the class. The explicitly initialized elements of the aggregate are the elements that are, or contain (in the case of an anonymous union or of a base class) those members.
304319
:::
305320

306321
:::
307322

308-
And extend [dcl.init.aggr]{.sref}/4 to cover base class elements:
323+
And extend [dcl.init.aggr]{.sref}/4 to cover base class elements (TODO: do we need this special case first bullet? Expand the designated-initializer-list bullet instead of adding a new bullet. Probably only need to change 4.2):
309324

310325
::: std
311326
[4]{.pnum} For each explicitly initialized element:
312327

313328
::: addu
314-
* [4.0]{.pnum} If the initializer list is a brace-enclosed *designated-initializer-list* with no `$initializer-list$` and the element is a direct base class, then let `C` denote that direct base class and let `T` denote the class. The element is initialized from a synthesized brace-enclosed *designated-initializer-list* containing each *designator* for which lookup in `T` names a direct or indirect non-static data member of `C` in the same order as in the original *designated-initializer-list*.
329+
* [4.0]{.pnum} If the initializer list is a brace-enclosed `$designated-initializer-list$` with no `$braced-init-list$` and the element is a direct base class, then let `C` denote that direct base class and let `T` denote the class. The element is initialized from a synthesized brace-enclosed *designated-initializer-list* containing each *designator* for which lookup in `T` names a (direct or indirect) non-static data member of `C` in the same order as in the original *designated-initializer-list*.
315330

316331
::: example
317332
```
318333
struct A { int a; };
319334
struct B : A { int b; };
320335
struct C : B { int c; };
321336
322-
// the A element is intialized from {.a=1}
337+
// the A element is initialized from {.a=1}
323338
B x = B{.a=1};
324339
325340
// the B element is initialized from {.a=2, .b=3}
@@ -367,7 +382,7 @@ Extend [dcl.init.list]{.sref}/3.1:
367382

368383
::: std
369384
[3.1]{.pnum} If the _braced-init-list_ contains a _designated-initializer-list_, `T` shall be an aggregate class.
370-
The ordered *identifier*s in the designators of the *designated-initializer-list* shall form a subsequence of [designatable members [(dcl.init.aggr)] of `T`.]{.addu}
385+
The ordered *identifier*s in the designators of the *designated-initializer-list* shall form a subsequence of [the ordered `$identifiers$` in the direct non-static data members]{.rm} [the designatable members [(dcl.init.aggr)] of `T`.]{.addu}
371386

372387
Aggregate initialization is performed ([dcl.init.aggr]).
373388

@@ -423,7 +438,7 @@ Bump `__cpp_­designated_­initializers` in [cpp.predefined]{.sref}:
423438
::: std
424439
```diff
425440
- __cpp_­designated_­initializers @[201707L]{.diffdel}@
426-
+ __cpp_­designated_­initializers @[2024XXL]{.diffins}@
441+
+ __cpp_­designated_­initializers @[2025XXL]{.diffins}@
427442
```
428443
:::
429444

0 commit comments

Comments
 (0)