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 a
Perfectly legal.
The object will exist on the stack during the function call, just like any other local variable as well.