If a template class whose parent is a template class tries to call a template method using the normal this->methodname<T>() syntax, g++ fails to parse the source file (details below).
-- begin test case file bug.cpp -- #define BUG_HERE class T1; //class A declares a template method class A { public: template <class X> void test() { } }; //class B is derived from class A template<class Y> class B : public A { public: void works() { //class B can still call the template method from class A this->test<T1>(); } }; template<class Y> class C : public B<Y> { public: void does_not_work() { #ifdef BUG_HERE this->test<T1>(); //unlike for class B, for class C, this does not work // with g++ (Ubuntu 4.4.3-4ubuntu5) 4.4.3 #endif A::test<T1>(); //this seems to compile } }; -- end -- $ g++ -v -save-temps -c bug.cpp Using built-in specs. Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.4.3-4ubuntu5' --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-plugin --enable-objc-gc --disable-werror --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.3 (Ubuntu 4.4.3-4ubuntu5) COLLECT_GCC_OPTIONS='-v' '-save-temps' '-c' '-shared-libgcc' '-mtune=generic' /usr/lib/gcc/x86_64-linux-gnu/4.4.3/cc1plus -E -quiet -v -D_GNU_SOURCE bug.cpp -D_FORTIFY_SOURCE=2 -mtune=generic -fpch-preprocess -fstack-protector -o bug.ii ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu" ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/4.4.3/../../../../x86_64-linux-gnu/include" ignoring nonexistent directory "/usr/include/x86_64-linux-gnu" #include "..." search starts here: #include <...> search starts here: /usr/include/c++/4.4 /usr/include/c++/4.4/x86_64-linux-gnu /usr/include/c++/4.4/backward /usr/local/include /usr/lib/gcc/x86_64-linux-gnu/4.4.3/include /usr/lib/gcc/x86_64-linux-gnu/4.4.3/include-fixed /usr/include End of search list. COLLECT_GCC_OPTIONS='-v' '-save-temps' '-c' '-shared-libgcc' '-mtune=generic' /usr/lib/gcc/x86_64-linux-gnu/4.4.3/cc1plus -fpreprocessed bug.ii -quiet -dumpbase bug.cpp -mtune=generic -auxbase bug -version -fstack-protector -o bug.s GNU C++ (Ubuntu 4.4.3-4ubuntu5) version 4.4.3 (x86_64-linux-gnu) compiled by GNU C version 4.4.3, GMP version 4.3.2, MPFR version 2.4.2-p1. GGC heuristics: --param ggc-min-expand=98 --param ggc-min-heapsize=128001 GNU C++ (Ubuntu 4.4.3-4ubuntu5) version 4.4.3 (x86_64-linux-gnu) compiled by GNU C version 4.4.3, GMP version 4.3.2, MPFR version 2.4.2-p1. GGC heuristics: --param ggc-min-expand=98 --param ggc-min-heapsize=128001 Compiler executable checksum: 88858f45841827736473e527a4e9ab10 bug.cpp: In member function void C<Y>::does_not_work(): bug.cpp:34: error: expected primary-expression before > token bug.cpp:34: error: expected primary-expression before ) token While there are workarounds for this bug, it is certainly unexpected behavior. Note that this bug does not occur for class B or for cases where class C is not a template class. -- Summary: Cannot call template method from derived template class Product: gcc Version: 4.4.3 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: klenze at mpp dot mpg dot de 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=44138