------- Comment #16 from bangerth at dealii dot org 2007-05-08 17:25 ------- (In reply to comment #14) > Which was wrong, I reported the bug and a guy from MinGW kindly explained that > if it worked then that would be purely by accident and added: > " When you declare the argument without '&' then it will make a temporary copy > of the Automobile object on the stack, but it is wrong to store a reference to > a temporary object because it will be invalid after the constructor > returns.".
You misunderstand my point: the international C++ standard quite clearly specifies under what circumstances a program is what it calls "ill-formed" and when a compiler has to issue an error. Taking the address of a temporary is completely valid according to this standard (i.e. it conforms to the *syntax* of the C++ language), and consequently a compiler can't issue an error. The fact that the program does something you may not expect, i.e. that the *semantics* are not what you want, is an entirely different matter. In this case, the C++ standard says that the behavior of your program is undefined. Compilers may warn about this, but they may not issue an error. W. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=986