[Bug c++/51270] constness violation is accepted without any warning but leads to a required function call being eliminated during optimization
redi at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Tue Nov 22 16:10:00 GMT 2011
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.
More information about the Gcc-bugs
mailing list