The following code will not compile under GCC 3.3, 3.3.1 (prerelease, 2003/07/20 snapshot), or 3.4 (cvs head as of 2003/07/29). template<class H, class T> struct TL {}; template<class X> class Base; template<class H, class T> class Base< TL<H,T> > { public: template<int I> void f() {} }; template<class H, class T> class Derived : public Base< TL<H,T> > { public: void g() { f<1>(); } }; KCC 4.0f --strict compiles this code, which is some evidence that the code is in fact legal. The problem seems to be that class Derived isn't actually inheriting from the specialized Base variant, or at least, name lookup is failing to find the (template) member function f().
This is correct behavior per the standard. The base class is dependent; therefore name lookup does look into the base class. See gcc/doc/trouble.texi for more information.
I stand corrected. And thanks for pointing me to the explanation, as it was good to be reminded of that. However, if I make the suggested correction to the call site to make the reference dependent, GCC still fails to compile the (corrected) code. For example, if we try template<class H, class T> class Derived : public Base< TL<H,T> > { public: void g() { this->f<1>(); } }; Then gcc 3.3.1 (prerelease) gives: /opt/gcc-3.3.1/bin/c++ -v -c x.cc Reading specs from /opt/gcc-3.3.1/lib/gcc-lib/i686-pc-linux-gnu/3.3.1/specs Configured with: ./configure --prefix=/opt/gcc-3.3.1 : (reconfigured) ./configure --prefix=/opt/gcc-3.3.1 --enable-languages=c,c++,f77 Thread model: posix gcc version 3.3.1 20030720 (prerelease) ... x.cc: In member function `void Derived<H, T>::g()': x.cc:20: error: parse error before `;' token which I think is the same error message as before, and gcc 3.4 (cvs head) gives: /opt/gcc-3.4/bin/c++ -v -c x.cc Reading specs from /opt/gcc-3.4/lib/gcc-lib/i686-pc-linux-gnu/3.4/specs Configured with: ./configure --prefix=/opt/gcc-3.4 : (reconfigured) ./configure --prefix=/opt/gcc-3.4 --enable-languages=c,c++,f77,java Thread model: posix gcc version 3.4 20030729 (experimental) ... x.cc: In member function `void Derived<H, T>::g()': x.cc:20: error: expected primary-expression Similarly, if we qualify the call site in this way: template<class H, class T> class Derived : public Base< TL<H,T> > { public: void g() { Base< TL<H,T> >::f<1>(); } }; which if I understand the trouble.texi correctly, should also be a legal way to introduce the dependency, then it still fails to compile with the same errors as with this->, quoted above, for all versions of gcc 3.2 through 3.4. Consequently, I am reopening the bug.
With icc 6.0 in strict mode (-Xc) icc rejects this after adding this-> or Base< TL<H,T> >:: before f<1>. The code is still invalid as f is template but the standard says it is not a template so adding template in front of f<1> fixes it. template<class H, class T> class Derived : public Base< TL<H,T> > { public: void g() { Base< TL<H,T> >::template f<1>(); // or this->template f<1>(); } };
*** Bug 11759 has been marked as a duplicate of this bug. ***