Specifically, is the following legal C++?
class A{}; void foo(A*); void bar(const A&); int main(void) { foo(&A()); // 1 bar(A()); // 2 }
It appears to work correctly, but that doesn’t mean it’s necessarily legal. Is it?
Edit – changed A& to const A&
1: Taking the address of a temporary is not allowed. Visual C++ allows it as a language extension (language extensions are on by default).
2: This is perfectly legal.