Skip to content

Remove incorrect class.union.assignment.not.start.lifetime #7833

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: ub-ifndr
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion source/classes.tex
Original file line number Diff line number Diff line change
Expand Up @@ -3237,7 +3237,7 @@
each anonymous union member \tcode{X}\iref{class.union.anon} that
is a member of a union and
has such an element as an immediate subobject (recursively),
if modification of \tcode{X} would have undefined behavior\ubdef{class.union.assignment.not.start.lifetime} under~\ref{basic.life},
if modification of \tcode{X} would have undefined behavior under~\ref{basic.life},
an object of the type of \tcode{X} is implicitly created
in the nominated storage;
no initialization is performed and
Expand Down
31 changes: 0 additions & 31 deletions source/ub.tex
Original file line number Diff line number Diff line change
Expand Up @@ -1242,37 +1242,6 @@
\end{example}


\rSec2[ub.class.union]{Unions}

\pnum
\ubxref{class.union.assignment.not.start.lifetime} \\
Assigning to a union member may not start its lifetime, in that case using it will result in undefined behavior.

\pnum
\begin{example}
\begin{codeblock}
struct X {
const int a;
int b;
};

union Y {
X x;
int k;
};

void g() {
Y y = {{1, 2}}; // OK, \tcode{y.x} is active union member\iref{class.mem}
int n = y.x.a;
y.k = 4; // OK, ends lifetime of \tcode{y.x}, \tcode{y.k} is active member of union
y.x.b = n; // undefined behavior: \tcode{y.x.b} modified outside its lifetime,
// \tcode{S(y.x.b)} is empty because \tcode{X}'s default constructor is deleted,
// so union member \tcode{y.x}'s lifetime does not implicitly start
}
\end{codeblock}
\end{example}


\rSec2[ub.class.abstract]{Abstract classes}

\pnum
Expand Down