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
[expr.comma, class.base.init] What is "temporary expression"? #1910
Comments
I used this term "temporary expression" in my DR with the meaning of what now is simply a prvalue expression and compared it with "bitfield lvalue", where "bitfield" is also a property of the (lvalue) expression and influences the compilation (for example it can result in illformed reference binding attempts). In [class.base.init] we actually must not use "temporary object", but need to say "prvalue expression" or "xvalue result of the temporary materialization conversion" or something to that effect, because in general the properties of objects referred-to by glvalues are unknown at compile time (including whether they are temporary objects or not). |
I think ideally [class.base.init]/8 and /11 should make a member initialization ill-formed when and only when the initialization is a reference binding described in [class.temporary]/6 ("when a reference is bound to a temporary object"). That is, it should not prohibit Using "xvalue result of the temporary materialization conversion" seems to work, but is less helpful, since it fails to catch some of the cases listed in [class.temporary]/6. |
I missed the nuances of [class.temporary]. What I thought the term "temporary expression" means is decoded in those bullets. However the "exceptions" listed after those bullets are defective (as far as I can tell), since they stop constraining the expression to have such a form. The rule "A temporary object bound to a reference parameter in a function call persists until the completion of the full-expression containing the call." can apply to the function call in this snippet:
My inquiry is that when we fix [class.base.init], we should be more precise. Perhaps [class.base.init] and the exceptions in [class.temporary]/6 should be fixed together as to avoid this kind of ambiguity. Requiring the reference binding to be one that is described in those bullets seem to work fine, as in
|
Editorial meeting consensus: drop "temporary expression" from expr.comma. For the reference binding cases, we say "bound to a temporary object whose lifetime would be extended (class.temporary], program is ill-formed". |
[expr.comma] has already been fixed. |
cplusplus/CWG#200 is a duplicate, IIUC. |
The phrase "temporary expression" does not seem to be a defined term. It is used in the following contexts:
[expr.comma]/1:
[class.base.init]/8:
[class.base.init]/11:
The sentence in [expr.comma]/1 was added by CWG 462 and has editorial adjustments applied later. CWG 462 should probably be superseded by CWG 1299 and thus that sentence could be removed.
The ones in [class.base.init] could probably say "temporary object" rather than "temporary expression".
The text was updated successfully, but these errors were encountered: