https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77615
--- Comment #3 from Markus Trippelsdorf <trippels at gcc dot gnu.org> --- The compiler only sees single compilation units and it doesn't keep a database of previously seen units. When it compiles usage.cc it doesn't know anything about specialization.cc. So there really is nothing that the compiler could do here. And clang and other compilers also don't warn and behave exactly like gcc once you use -O2.