cplusplus / draft

C++ standards drafts
http://www.open-std.org/jtc1/sc22/wg21/
5.65k stars 746 forks source link

[class.temporary] Clarify wording for lifetime of temporaries. #6562

Open leni536 opened 1 year ago

leni536 commented 1 year ago

Current wording

https://github.com/cplusplus/draft/blob/16c8ce5db2173a098a91e552dcfa3544c67e544f/source/basic.tex#L4379-L4383

As far as I know "(lexically) contained" is not defined.

The presence of "lexically" here is especially confusing in the light of this note:

https://github.com/cplusplus/draft/blob/16c8ce5db2173a098a91e552dcfa3544c67e544f/source/basic.tex#L5824-L5831

Intent

I think the intent is pretty clear in light of the subexpression wording and corresponding examples that the lifetime of a temporary should be solely be determined by the corresponding full-expression of the temporary materialization conversion subexpression that initialized it. Any "lexical" relationship is incidental.

Suggested wording

I think the [class.temporary] wording can be expressed purely with subexpressions, like so:

At the end of a full-expression temporaries that are initialized by temporary materialization conversion [conv.rval] subexpressions are destroyed.

frederick-vs-ja commented 1 year ago

It seems that we should cover both subexpressions and constituent expressions.

Is it clear enough to say the following?

Temporary objects are destroyed as the last step in evaluating the full-expression ([intro.execution]) ~that (lexically) contains the point where they were created~ of the temporary materialization conversions ([conv.rval]) that initialized the temporary objects.

leni536 commented 12 months ago

It seems that we should cover both subexpressions and constituent expressions.

You are probably right

Is it clear enough to say the following?

Temporary objects are destroyed as the last step in evaluating the full-expression ([intro.execution]) ~that (lexically) contains the point where they were created~ of the temporary materialization conversions ([conv.rval]) that initialized the temporary objects.

What's a "full-expression of "? I guess it's meant to be the inverse relationship of "subexpression or constituent expression of ", but I don't think it's defined anywhere. I think your proposed wording would be clear if "full-expression of" also gets defined elsewhere.

Alternatively the following wording could be used.

As the last step in evaluating a full-expression the temporaries that are initialized [conv.rval] in subexpressions or constituent expressions of the full-expression are destroyed.