The program below fails to link with gcc 4.0.2. See also the closely related bug 22263 (fixed in 4.0.2).
$ cat a.cpp && g++ -c a.cpp && g++ -DMAIN a.cpp a.o template <class T> struct S { T foo (); T bar (); }; template <class T> T S<T>::foo () { return T (); }; #ifndef MAIN template struct S<int>; #else extern template struct S<int>; int main () { return S<int>().foo () + S<int>().bar () ; } #endif template <class T> T S<T>::bar () { return T (); }; Undefined first referenced symbol in file S<int>::bar() /var/tmp//ccAahmFW.o ld: fatal: Symbol referencing errors. No output written to a.out collect2: ld returned 1 exit status -- Summary: explicit instantiation/extern template unsats on symbols defined later Product: gcc Version: 4.0.2 Status: UNCONFIRMED Severity: critical Priority: P2 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: sebor at roguewave dot com GCC build triplet: sparc-sun-solaris2.9 GCC host triplet: sparc-sun-solaris2.9 GCC target triplet: sparc-sun-solaris2.9 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24511