Skip to content
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

[basic.life] Add cross-reference for union member lifetime #5228

Merged
merged 1 commit into from Sep 9, 2022

Conversation

jensmaurer
Copy link
Member

Fixes #5219

@jensmaurer
Copy link
Member Author

@zygoloid , I think this is right, but I'd appreciate your review.

@languagelawyer
Copy link
Contributor

languagelawyer commented Jan 22, 2022

Usually, when a standard defines a general rule and, in other sections, has rules overriding it for some specific cases, the generic rule does not (normatively) enumerate exceptions. Why [basic.life]/1 shall be an exception?

@xmh0511
Copy link
Contributor

xmh0511 commented Jan 28, 2022

Usually, when a standard defines a general rule and, in other sections, has rules overriding it for some specific cases, the generic rule does not (normatively) enumerate exceptions. Why [basic.life]/1 shall be an exception?

Because the general rule uses the wording: only begins, and it also didn't say such as except/unless otherwise specified. In a contrast, [basic.lookup] says

Unless otherwise specified, the program is ill-formed if no declarations are found.

The clause didn't cover the dependent names in a template definition, but it does say: Unless otherwise specified, which means there can exist an exception, in other places, that [basic.lookup] does not explicitly list it.

Thus, that general rule should be responsible to enumerate all the cases.

@wg21bot wg21bot added the needs rebase The pull request needs a git rebase to resolve merge conflicts. label Feb 22, 2022
Comment on lines 3354 to +3356
initialized member in the union\iref{dcl.init.aggr,class.base.init},
or as described in \ref{class.union} and \ref{class.copy.ctor},
or as described in
\ref{class.union}, \ref{class.copy.ctor}, and \ref{class.copy.assign},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of these cases, only [class.copy.ctor] (calling a union copy constructor) starts the lifetime of the union member subobject. Both the [class.union] (assigning to a union member) and [class.copy.assign] (assigning to a union) cases create a new object that transparently replaces the union member. So I think only [class.copy.ctor] is in scope here, although the reason for that is subtle.

Copy link
Member

@zygoloid zygoloid Sep 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose another viewpoint is that, because the newly-created object transparently replaces a union member subobject, it is itself a member subobject ([intro.object]p2), and so it is in the scope of this rule, in which case this change seems appropriate. Either way, we should be consistent: either both [class.union] and [class.copy.assign] should be listed here or neither of them.

Given the existing state of this wording, accepting the proposed change seems reasonable to me.

@tkoeppe
Copy link
Contributor

tkoeppe commented Sep 8, 2022

Thank you, @zygoloid! @jensmaurer, I suppose we'll take this as-is then? I'm sure I don't appreciate all the subtleties here, so I'll take your word for it.

@jensmaurer
Copy link
Member Author

@tkoeppe, I think we should take this as-is.

@tkoeppe tkoeppe merged commit 7260f30 into cplusplus:main Sep 9, 2022
@jensmaurer jensmaurer deleted the c39 branch September 9, 2022 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[basic.life] p1 omits a cross-reference to [class.copy.assign] for union member case
6 participants