http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51270
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-11-22 15:50:33 UTC --- If you eliminate the obfuscation you get this: int*& faulty_compiled_function(char*& val) { char const* tmp = val; return (int*&)tmp; } char* input = (char*)0x1234; int* output = (int*)0x1234; int main(int argc, char* argv[]) { return (faulty_compiled_function(input) == output ? 0 : 1); } Which correctly warns you about the problem even without -Wall If there's a bug in GCC it's that it doesn't see through two layers of functions to determine that you're returning a reference to a temporary.