consider the following example program:
#include <iostream>
using namespace std;
struct t
{
~t() {cout << "destroyed\n"; }
};
int main()
{
cout << "test\n";
t(), cout << "doing stuff\n";
cout << "end\n";
}
The output I get with GCC 4.9.2 is:
test
doing stuff
destroyed
end
cpp.sh link: http://cpp.sh/3cvm
However according to cppreference about the comma operator:
In a comma expression E1, E2, the expression E1 is evaluated, its result is discarded, and its side effects are completed before evaluation of the expression E2 begins
I'd expect ~t()
to be called before cout << "doing stuff"
Is this a standard behavior? If so, where is it defined in the standard?