Repository navigation
[intro.execution] CWG2431: Destruction of a temp. object bound to a reference is not a full-expression? #2664
Description
Activity
If you have multiple lifetime-extended temporaries, do their destructors produce multiple full-expressions?
{ const auto& rk = Klass{}; const auto& rk2 = Klass{}; // ... }The current wording seems to allow the destructor invocations
rk.~Klass()andrk2.~Klass()to be part of the same full-expression (though it could be clearer whether that is intended, or whether your reading is correct).If you have multiple lifetime-extended temporaries, do their destructors produce multiple full-expressions?
If I have multiple non-reference variables, do their destruction produce multiple full-expressions?
Yes, but the destruction of temporary objects doesn't have to produce multiple full-expressions, so there's no inherent requirement that destruction of objects happens in separate full-expressions.
Ok, the difference could be intended, lets wait what others will say.
The text is clearly wrong (a lifetime-extended temporaries should be treated as-if it were a non-reference variable), but is the fix editorial?
- addeddecision-requiredA decision of the editorial group (or the Project Editor) is required.A decision of the editorial group (or the Project Editor) is required.
on Feb 10, 2019 Given the ambiguity Jonathan mentioned, I think we should process this as a core issue.
- addedcwgIssue must be reviewed by CWG.Issue must be reviewed by CWG.and removeddecision-requiredA decision of the editorial group (or the Project Editor) is required.A decision of the editorial group (or the Project Editor) is required.
on Feb 10, 2019 @jensmaurer the difference would be observable if a destructor throws an exception.
@languagelawyer, sorry, maybe it's too early in the morning for me, but could you please be more specific?
@jensmaurer if there are several temporary object destructor invocations in one full-expression and one of them throws an exception, it will finish evaluating the rest of the full-expression and could left some destructors not invoced. But if each destructor invocation is a full-expression and one of them thows, the following destructors still would be called during stack unwinding.
@languagelawyer: Such behavior would be at odds with [stmt.jump] p2: Even if a destructor throws an exception, you still need to execute the rest of the destructors, now in the context of stack unwinding [except.ctor].
@jensmaurer hm, indeed. Then I also don't see a difference.
I'm not aware of any way the difference is observable, so maybe it can be changed editorially (or maybe it doesn't need to change at all). My original comment was just to say that "it is intended to be a full-expression" may need additional justification, as it's not obvious to me whether that really is the intention.
- changed the title
[-][intro.execution] Destruction of a temp. object bound to a reference is not a full-expression?[/-][+][intro.execution] CWG2431: Destruction of a temp. object bound to a reference is not a full-expression?[/+]on Sep 16, 2019 - addednot-editorialIssue is not deemed editorial; the editorial issue is kept open for tracking.Issue is not deemed editorial; the editorial issue is kept open for tracking.
on Sep 16, 2019
http://eel.is/c++draft/intro.execution#def:full-expression:
Here is an example
I think it is intended to be a full-expression, so the Standard should say something like