Case 1: The following code is rejected by GCC 4.0.1 and GCC 4.0.0:
=== begin === template < class C, class T > struct A { template < class G > void f( G& g ) { g.f1(); } }; // (a) template < class T > // (c) template < class G > void A< char, T >::f( G& g ) // (b) { g.f2(); } === end === The compiler says "error: no member function 'f' declared in 'A<char, T>'" and "error: invalid function declaration" at point (b). Case 2: But if a partial specialization of class template A, as below, is inserted at point (a) in case 1, the compilers accept the code: === begin === template < class T > struct A< char, T > { template < typename G > void f( G& g ); }; === end === Case 3: The compiler also accepts the code if the function definition at point (c) in case 1 is defined as below, even without the partial specialization of class template A in case 2: === begin === template <> template < class G > void A< char, int >::f( G& g ) { g.g2(); } === end === Case 4: If the member function f() is not a template, as below, the error messages are "error: invalid use of undefined type 'A<char, T>'" at point (d), "error: declaration of struct 'A<char, T>'" at point (e), and "error: template definition of non-template 'void A<char, T>::f()'" at point (d): === begin === template < class C, class T > struct A { // (d) void f() {} }; template < class T > void A< char, T >::f() // (e) {} === end === The compilers tested are Debian 4.0.0-7: === begin === Using built-in specs. Target: i486-linux Configured with: ../src/configure -v --enable-languages=c,c++,java,f95,objc,ada,treelang --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --enable-nls --without-included-gettext --enable-threads=posix --program-suffix=-4.0 --enable-__cxa_atexit --enable-libstdcxx-allocator=mt --enable-clocale=gnu --enable-libstdcxx-debug --enable-java-gc=boehm --enable-java-awt=gtk --enable-mpfr --disable-werror --enable-checking=release i486-linux Thread model: posix gcc version 4.0.1 20050509 (prerelease) (Debian 4.0.0-7) === end === and Debian 4.0.1-1: === begin === Using built-in specs. Target: i486-linux-gnu Configured with: ../src/configure -v --enable-languages=c,c++,java,f95,objc,ada,treelang --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --enable-nls --without-included-gettext --enable-threads=posix --program-suffix=-4.0 --enable-__cxa_atexit --enable-libstdcxx-allocator=mt --enable-clocale=gnu --enable-libstdcxx-debug --enable-java-gc=boehm --enable-java-awt=gtk --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-4.0-1.4.2.0/jre --enable-mpfr --disable-werror --enable-checking=release i486-linux-gnu Thread model: posix gcc version 4.0.1 (Debian 4.0.1-1) === end === -- Summary: member function template of partial specialized class template Product: gcc Version: 4.0.1 Status: UNCONFIRMED Severity: normal Priority: P2 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: zhaojiangbin at yahoo dot com CC: gcc-bugs at gcc dot gnu dot org GCC host triplet: i486-linux-gnu GCC target triplet: i486-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22427