https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100430
Martin Sebor <msebor at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |msebor at gcc dot gnu.org --- Comment #3 from Martin Sebor <msebor at gcc dot gnu.org> --- At -O3 the call to f() is inlined earlier and the whole if statement in f() is eliminated before the warning runs. The store is eliminated because c is static and nothing reads from it. When it's made extern the store is retained and the warning shows up at -O3 too. At -O2 early inlining fails with: will not early inline: void h()/3->void f(char*&)/2, growth 5 exceeds --param early-inlining-insns divided by number of calls Iterations: 0 Bumping up the early-inlining-insns parameter inlines the function at -O2 and the warning disappears then too. All these interactions with the optimizers are inherent in the middle end warnings because they so heavily depend on them. The static analyzer can do better because it doesn't depend on the optimizers.