The following C++ code compiles (but doesn't link) with g++ 4.3.1: template <typename T_> struct B { T_ f(); };
extern template class B<int>; void f() { B<int> t; t.f(); } With 'gcc () 4.4.0-pre9999 built 20080827 (Gentoo SVN ebuild) rev. 139623', the following error occurs: $ g++ -O1 a.cc a.cc: In instantiation of T_ B<T_>::f() [with T_ = int]: a.cc:12: instantiated from here a.cc:12: error: explicit instantiation of T_ B<T_>::f() [with T_ = int] but no definition available If no -O is specified, the error does not occur. Using -std=c++0x does not alter the outcome. I'm looking at n2723 14.7.2 for what the behaviour should be. My understanding is as follows: By paragraph 7, the explicit instantiation declaration for B<int> is also an explicit instantiation declaration for int B<int>::f(). Thus, by paragraph 3, a definition of B<int> must be available when declaring int B<int>::f(), which it is. But I don't see a requirement for a definition of B<int>::f(). -- Summary: extern template / explicit instantiation broken in 4.4.0-pre Product: gcc Version: 4.4.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: ciaran dot mccreesh at googlemail dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37256