Nya*_*hes 8 c++ object-lifetime comma-operator language-lawyer temporary-objects
考虑以下示例程序:
#include <iostream>
using namespace std;
struct t
{
~t() {cout << "destroyed\n"; }
};
int main()
{
cout << "test\n";
t(), cout << "doing stuff\n";
cout << "end\n";
}
Run Code Online (Sandbox Code Playgroud)
我从GCC 4.9.2获得的输出是:
test
doing stuff
destroyed
end
Run Code Online (Sandbox Code Playgroud)
cpp.sh链接:http://cpp.sh/3cvm
但是根据关于逗号运算符的cppreference:
在逗号表达式E1,E2中,评估表达式E1,丢弃其结果,并且在评估表达式E2开始之前完成其副作用
我希望~t()
以前能打电话给我cout << "doing stuff"
这是标准行为吗?如果是这样,标准中的定义在哪里?