https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79001
Bug ID: 79001 Summary: spurious "defined but not used" warning with explicit instantiation Product: gcc Version: 6.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: jens.maurer at gmx dot net Target Milestone: --- The following testcase gives a "defined but not used" warning for "f", but not for "g". I agree that "f" cannot be used outside of the translation unit (due to the use of a type from an anonymous namespace), but neither can "g". Plus, if someone does use explicit instantiations on a class, it does not seem helpful to produce "unused function" warnings for functions generated from an explicit instantiation on a class in the first place, because the class (maybe from a library) might have a lot more member functions than actually in use in any given file. template <class T> class C { void f(); void g() { } }; template<class T> void C<T>::f() { } namespace { struct X { }; } template class C<X>; V$ gcc -Wunused-function -c x.cc x.cc:9:6: warning: ‘void C<T>::f() [with T = {anonymous}::X]’ defined but not used [-Wunused-function] void C<T>::f() { } ^~~~