The following code compiles without error and lead to a seg fault at runtime:
template <class U, class V> struct A; template <class V> struct A<int, V> { void f(); }; template struct A<int, int>; int main() { A<int, int> a; a.f(); return 0; } Notice that there is no body defined for A<int, int>::f(). The correct link error is reported when no explicit template instantiation is requested: /tmp/ccycZSyE.o: In function `main': testcase.cpp:(.text+0x10): undefined reference to `A<int, int>::f()' collect2: ld returned 1 exit status $g++ -v Using built-in specs. Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Debian 4.4.2-7' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --program-suffix=-4.4 --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --with-arch-32=i486 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix gcc version 4.4.2 (Debian 4.4.2-7) -- Summary: Undefined reference not reported in case of explicit template instantiation Product: gcc Version: 4.4.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: bastien_emmanuel at yahoo dot fr GCC build triplet: x86_64-linux-gnu GCC host triplet: x86_64-linux-gnu GCC target triplet: x86_64-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42608