full-expression

C++ 17 full-expression standard definition

流过昼夜 提交于 2019-12-10 23:32:00
问题 This paragraph from the C++ 17 standard draft states, among others, that: A full-expression is: -an unevaluated operand, -a constant-expression ([expr.const]), -an init-declarator ([dcl.decl]) or a mem-initializer ([class.base.init]), including the constituent expressions of the initializer, -an invocation of a destructor generated at the end of the lifetime of an object other than a temporary object, or -an expression that is not a subexpression of another expression and that is not

Full-expression boundaries and lifetime of temporaries [duplicate]

时光怂恿深爱的人放手 提交于 2019-11-30 08:27:12
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: C++: Life span of temporary arguments? It is said that temporary variables are destroyed as the last step in evaluating the full-expression, e.g. bar( foo().c_str() ); temporary pointer lives until bar returns, but what for the baz( bar( foo().c_str() ) ); is it still lives until bar returns, or baz return means full-expression end here, compilers I checked destruct objects after baz returns, but can I rely on

Full-expression boundaries and lifetime of temporaries [duplicate]

拈花ヽ惹草 提交于 2019-11-29 06:28:52
Possible Duplicate: C++: Life span of temporary arguments? It is said that temporary variables are destroyed as the last step in evaluating the full-expression, e.g. bar( foo().c_str() ); temporary pointer lives until bar returns, but what for the baz( bar( foo().c_str() ) ); is it still lives until bar returns, or baz return means full-expression end here, compilers I checked destruct objects after baz returns, but can I rely on that? Temporaries life until the end of the full expression in which they are created. A "full expression" is an expression that's not a sub-expression of another

Lifetime of temporaries

喜欢而已 提交于 2019-11-26 00:25:51
问题 The following code works fine, but why is this correct code? Why is the \"c_str()\" pointer of the temporary returned by foo() valid? I thought, that this temporary is already destroyed when bar() is entered - but it doesn\'t seem to be like this. So, now I assume that the temporary returned by foo() will be destroyed after the call to bar() - is this correct? And why? std::string foo() { std::string out = something...; return out; } void bar( const char* ccp ) { // do something with the