Sequencing of function parameter destruction

不羁岁月 提交于 2019-12-01 02:28:19

Actually I can answer my own question... didn't find an answer while searching before writing it, but then searching again afterwards did find an answer (typical huh).

Anyway: this issue is CWG #1880 with the resolution:

Notes from the June, 2014 meeting:

WG decided to make it unspecified whether parameter objects are destroyed immediately following the call or at the end of the full-expression to which the call belongs.

The latest C++17 draft that I have (N4606) has changed the text in [expr.call]/4:

It is implementation-defined whether the lifetime of a parameter ends when the function in which it is defined returns or at the end of the enclosing full-expression.

I guess we should treat this resolution (i.e. "implementation-defined") as applying retroactively , since it was not well specified by published standards.

Note: The definition of full-expression can be found in C++14 [intro.execution]/10:

A full-expression is an expression that is not a subexpression of another expression. [...] If a language construct is defined to produce an implicit call of a function, a use of the language construct is considered to be an expression for the purposes of this definition.

So F v { func(0) }; is the enclosing full-expression for gparm (even though it's a declaration and not an expression!).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!