http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58240
Jakub Jelinek <jakub at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jakub at gcc dot gnu.org --- Comment #12 from Jakub Jelinek <jakub at gcc dot gnu.org> --- Removing of strncmp in your bogus testcase because its result is unused doesn't happen only because you override strncmp in the same compilation unit and before it is eliminated it your code is inlined. If you compile with -O2 -fno-inline or redefine strncmp in a different CU, both strncmp calls will be optimized away. The C and C++ standard describe exactly what the functions like strncmp do, and your testcase doesn't do that, both because it returns unconditionally 0 even when the arguments aren't the same in the length, uses invalid type for the last argument (it should be size_t) and has user visible side effect that it shouldn't. So, if you want this to work, you really need to pass a non-standard option (-fno-builtin or -fno-builtin-strncmp) to tell gcc you are not compiling a valid program and force it not to optimize it.