http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51270
Jonathan Wakely <redi at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Summary|constness violation is |missed warning about |accepted without any |returning reference to |warning but leads to a |temporary |required function call | |being eliminated during | |optimization | --- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-11-22 16:41:16 UTC --- Very similar to my PR 49974. Still no warning even without the (highly questionable) cast: char const* const& faulty_compiled_function(char*& val) { char const* const& tmp = (const char*)val; return tmp; } N.B. Clang warns for that variation (but not the others): faulty_optimization_of_invalid_const_usage.cpp:4:10: warning: returning reference to local temporary object [-Wreturn-stack-address] return tmp; ^~~ faulty_optimization_of_invalid_const_usage.cpp:3:22: note: binding reference variable 'tmp' here char const* const& tmp = (const char*)val; ^ ~~~~~~~~~~~~~~~~