http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51270
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-11-22 15:47:45 UTC --- If you want warnings then you should request them using -Wall etc. Although doing so at -O2 gives this, which isn't actually very helpful: e.cpp:67:60: warning: '<anonymous>' is used uninitialized in this function [-Wuninitialized] There is no constness error, the argument to recast_reference creates a temporary of type 'char const*' which binds to a reference-to-const to that type: You can rewrite it as: int*& faulty_compiled_function(char*& val) { char const* tmp = pass_through(val); return recast_reference(tmp); } pass_through and recast_reference are not needed, they simply serve to hide the error in your code, which is that you return a reference to the temporary, and use it in main() after the temporary has gone out of scope. Therefore the code is invalid.