Consider this example
#include <iostream>
struct A{
A(){
std::cout<<"A ctor\n";
}
~A(){
std::cout<<"A dtor\n";
}
};
int fun(A const&){
std::cout<<"abc\n";
return 0;
}
void show(double, int){
std::cout<<"show\n";
}
int main() {
show(0,fun(A{})); // #1
}
According to the result, it is observable that the temporary object is destroyed at the completion of #1
. According to [class.temporary] p6
The exceptions to this lifetime rule are:
- A temporary object bound to a reference parameter in a function call ([expr.call]) persists until the completion of the full-expression containing the call.
I wonder why is show(0,fun(A{}));
the full-expression of fun(A{})
? According to [basic.exec#intro.execution-5]
A full-expression is
-[...]
- an expression that is not a subexpression of another expression and that is not otherwise part of a full-expression.
show(0,fun(A{}));
is a full-expression, however, the function call fun(A{})
that is an argument of the function call of show
is not a subexpression of the enclosing function call(if explicitly specified arguments are not operands of a function call). The definition of part of a full-expression is also not clear in the standard.
I have the following concerns:
- Are arguments considered to be operands of the function call?
the answers in C standard seems to say they are not
- What is the part of a full-expression?