The exact point in time at which parameters are destroyed is unspecified:
CWG 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 order in which parameters are constructed is unspecified as well, but because function parameters have block scope, although their order of construction is unspecified, destruction is in the reverse order of construction. E.g. consider
#include <iostream>
struct A {
int i;
A(int i) : i(i) {std::cout << i;}
~A() {std::cout << '~' << i;}
};
void f(A, A) {}
int main() {
(f(0, 1), std::cout << "#");
}
prints 10#~0~1
with GCC and 01#~1~0
with Clang; they construct parameters in different orders, but both destroy in the reverse order of construction, at the end of the full-expression the call occurs in (rather than right after returning to the caller). VC++ prints 10~0~1#
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…