A template class member function that is defined out-of-line with an associated explicit template instantiation is not instantiated by g++ 4.0.x. No warnings or error messages are given. Using earlier g++ versions, the member function is instantiated and placed in the object file.
Confirmed function is instantiated with g++ 3.3.0/linux, 3.4.4/cygwin Confirmed function is not instantiated with g++ 4.0.1/linux, 4.0.2/linux Source: // ATemplate.h template <class T> class ATemplate { T const n; public: ATemplate () : n (1) { } T GetValue () const; }; template class ATemplate<int>; // ATemplate.cpp #include "ATemplate.h" template <class T> T ATemplate<T>::GetValue () const { return n; } Compile: % g++ -c ATemplate.cpp Contents of object file: ----- g++ 3.4.4 (cygwin): % g++ -v Reading specs from /usr/lib/gcc/i686-pc-cygwin/3.4.4/specs Configured with: /gcc/gcc-3.4.4/gcc-3.4.4-1/configure --verbose --prefix=/usr --exec-prefix=/usr --sysconfdir= /etc --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --enable-langua ges=c,ada,c++,d,f77,java,objc --enable-nls --without-included-gettext --enable-version-specific-runtime-libs - -without-x --enable-libgcj --disable-java-awt --with-system-zlib --enable-interpreter --disable-libgcj-debug - -enable-threads=posix --enable-java-gc=boehm --disable-win32-registry --enable-sjlj-exceptions --enable-hash-s ynchronization --enable-libstdcxx-debug : (reconfigured) Thread model: posix gcc version 3.4.4 (cygming special) (gdc 0.12, using dmd 0.125) % nm -C ATemplate.o 00000000 T ATemplate<int>::ATemplate() 00000000 T ATemplate<int>::ATemplate() 00000000 T ATemplate<int>::GetValue() const ----- g++ 4.0.1 (Linux x86_64): % g++ -v Using built-in specs. Target: x86_64-unknown-linux-gnu Configured with: /home/nrel/ty/build/devel/gcc/gcc-4.0.1/configure --prefix=/usr2/OS-DEPENDENT/Linux_Generic_x86_64/gcc-4.0.1 Thread model: posix gcc version 4.0.1 % nm -C ATemplate.o 0000000000000000 W ATemplate<int>::ATemplate() 0000000000000000 W ATemplate<int>::ATemplate() U __gxx_personality_v0 -- Summary: template class method defined out-of-line is not instantiated Product: gcc Version: 4.0.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: tom dot hilinski at comcast dot net http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26786