File tree Expand file tree Collapse file tree 2 files changed +1
-32
lines changed
Expand file tree Collapse file tree 2 files changed +1
-32
lines changed Original file line number Diff line number Diff line change 32893289each anonymous union member \tcode {X}\iref {class.union.anon } that
32903290is a member of a union and
32913291has such an element as an immediate subobject (recursively),
3292- if modification of \tcode {X} would have undefined behavior\ubdef {class.union.assignment.not.start.lifetime} under~\ref {basic.life },
3292+ if modification of \tcode {X} would have undefined behavior under~\ref {basic.life },
32933293an object of the type of \tcode {X} is implicitly created
32943294in the nominated storage;
32953295no initialization is performed and
Original file line number Diff line number Diff line change 12001200\end {example }
12011201
12021202
1203- \rSec 2[ub.class.union]{Unions}
1204-
1205- \pnum
1206- \ubxref {class.union.assignment.not.start.lifetime } \\
1207- Assigning to a union member may not start its lifetime, in that case using it will result in undefined behavior.
1208-
1209- \pnum
1210- \begin {example }
1211- \begin {codeblock }
1212- struct X {
1213- const int a;
1214- int b;
1215- };
1216-
1217- union Y {
1218- X x;
1219- int k;
1220- };
1221-
1222- void g() {
1223- Y y = {{1, 2}}; // OK, \tcode {y.x} is active union member\iref {class.mem }
1224- int n = y.x.a;
1225- y.k = 4; // OK, ends lifetime of \tcode {y.x}, \tcode {y.k} is active member of union
1226- y.x.b = n; // undefined behavior: \tcode {y.x.b} modified outside its lifetime,
1227- // \tcode {S(y.x.b)} is empty because \tcode {X}'s default constructor is deleted,
1228- // so union member \tcode {y.x}'s lifetime does not implicitly start
1229- }
1230- \end {codeblock }
1231- \end {example }
1232-
1233-
12341203\rSec 2[ub.class.abstract]{Abstract classes}
12351204
12361205\pnum
You can’t perform that action at this time.
0 commit comments