Рассмотрим программу:
Код: Выделить всё
#include
#include
struct X
{
std::string tag;
~X() { std::println("X::~X() - {}", tag); }
};
X f(const X& x) {
std::println("f() - {}", x.tag);
return {x.tag + "!"};
}
int main() {
f(f({"x"}));
}
Код: Выделить всё
f() - x
f() - x!
X::~X() - x!!
X::~X() - x!
X::~X() - x
Обратите внимание, что
Код: Выделить всё
f()
Код: Выделить всё
X
Код: Выделить всё
X f(X x)
Код: Выделить всё
XОбъект
Код: Выделить всё
f() - x
X::~X() - x
f() - x!
X::~X() - x!
X::~X() - x!!
- [class.temporary#6.9]
([expr.call]) persists until the completion of the full-expression
containing the call.
- [class.temporary#8]
the full-expression in which it was created is sequenced before the
destruction of every temporary which is constructed earlier in the
same full-expression.
- [expr.call#6]
when the function in which it is defined returns or at the end of the
enclosing full-expression.
Источник: https://stackoverflow.com/questions/781 ... tion-calls