This is GCC Bugzilla
This is GCC Bugzilla Version 2.20+
View Bug Activity | Format For Printing | Clone This Bug
The 'template' disambiguator keyword on the base of B below causes the following error: "expected class-name before '{' token". This code compiles in GCC 3.3.1. Test case: struct A { template <class F> struct X { }; }; template <class F> struct B : public A::template X<F> { }; gcc -v output: Reading specs from /gcc-3.4/lib/gcc/i686-pc-cygwin/3.4.0/specs Configured with: ../gcc/configure --prefix=/gcc-3.4 --enable-languages=c,c++,f77 --enable-libgcj --enable-threads=posix --with-system-zlib --enable-nls --withou t-included-gettext --enable-interpreter --enable-version-specific-runtime-libs - -enable-shared --disable-win32-registry --enable-java-gc=boehm --disable-hash-sy nchronization --verbose Thread model: posix gcc version 3.4.0 20040312 (prerelease)
Confirmed a regression from 3.3.1.
I think I recall that the disambiguator was not allowed here. Giovanni, somehow I recall that you said that before, do you happen to know? W.
Yes, 'template' is disallowed outside of template definition, and the base class list is never part of the class definition. The rationale is that '<' can't be an operator< in that context. Anyway, I think Jason would agree to allow it if not pedantic, and a better error message would surely be desirable. I'm keeping this as an enhancement, and I will look into this.
Subject: Re: 'template' disambiguator on base class gives a bad error message "giovannibajo at libero dot it" <gcc-bugzilla@gcc.gnu.org> writes: | Yes, 'template' is disallowed outside of template definition, and the base | class list is never part of the class definition. The rationale is that '<' | can't be an operator< in that context. | | Anyway, I think Jason would agree to allow it if not pedantic, and a better | error message would surely be desirable. I agree with the better diagnostic part, but I do not for the "not pedantic" part. -- Gaby
In the following test case I receive an error message saying the use of the template disambiguator is required on the base of B::X. template <class T> struct A { template <class F> class X { }; }; template <class T> struct B { template <class F> class X : public A<T>::X<F> { }; }; --:15: error: non-template `X' used as template --:15: error: (use `A<T>::template X' to indicate that it is a template) --:17: error: expected `{' before ';' token Both Comeau C++ 4.3.3 and Intel Windows Compiler 8.0 accept the template disambiguator on base classes in all cases I have tried. --Ron
(In reply to comment #5) > In the following test case I receive an error message saying the use of the > template disambiguator is required on the base of B::X. This testcase is actually more interesting because it shows a real regression (valid code which is not accepted anymore by GCC). The diagnostic suggestion is wrong in this context, and the fix is obviously changing GCC to accept the code. So, we keep both the rejects-valid and the insufficient diagnostic for this PR. > Both Comeau C++ 4.3.3 and Intel Windows Compiler 8.0 accept the template > disambiguator on base classes in all cases I have tried. For this specific case, the EDG frontend (which is behind both the compiler you mentioned) is not a good test because it is very very loosy wrt both 'typename' and 'template', for instance you can mostly omit them and the code will still compile.
I'm closing this as a dup of PR 15503. The standard does not specify whether the code in comment #5 is invalid or not, as explained in PR 15503. This will be probably fixed in C++0x, and will be revised by then. *** This bug has been marked as a duplicate of 15503 ***