http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56762
Bug #: 56762 Summary: too aggressive optimization or missing warnings Classification: Unclassified Product: gcc Version: 4.7.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassig...@gcc.gnu.org ReportedBy: n...@chello.at Created attachment 29743 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=29743 code describing the issue Alternatively this could be just me misunderstanding C++. But the issue is that I have an object created on the stack and I would expect it to survive until it goes out of scope. Now I understand that I probably used it the wrong way by giving it a temporary when it needed a reference to something more solid, but I would expect an error message in this case. Please look at the provided code, which compiles without error/warning. the exchange function wont have any calls to lock/unlock. tested with gcc 4.7.2 + 4.8.0