Here's a spin-off from PR 6023: The following code snippet is wrongly accepted by gcc: ------------------------------------------- template <typename> struct A { template <typename> void foo(); }; template <typename T> struct B { template <int> void foo() { A<T>* p; p->foo<int>(); // wrong: should be "p->template foo<int>();" } }; ------------------------------------------- Since "p" is dependent on the outer template parameter, we need a "template" here. The parser wrongly accepts it because it finds "foo" in the current scope which happens to be a template (although it's actually the wrong "foo" that is considered for parsing). (This was pointed out by Nathan.) To see this effect, just remove the "template <int>" from the second "foo" and the compiler gioves an error message. This bug affects all versions since gcc 2.95.x.
I can confirm this on the mainline (20030805). Here is a more interesting example where the two template function foo take two different template arguments: template <typename> struct A { template <int> void foo(); }; template <typename T> struct B { template <int> void foo() { A<T>* p; p->foo<1>(); // wrong: should be "p->template foo<1>();" } };
My comment in 1 is wrong, the example I gave is where they have the same type template agruments not different.
Maybe related to PR 10200.
Probably problem deciding if a name is dependent.
Hmm, ICC 6.0 accepts the code also (even in strict mode).
*** Bug 20516 has been marked as a duplicate of this bug. ***
This can be simplified to: template <class T> void f() { T t; t.f<>(0); //should be t.template f<>(0); } If either 'f' is renamed g++ correctly reports an error. Comeau's online compiler behaves the same.
This is also related to PR 20308 (I think they are more than related, I think they are the same bug but reproducing in a different way).
Still accepts-invalid with 4.2-20070430 (RC2).
*** Bug 37596 has been marked as a duplicate of this bug. ***
*** Bug 41973 has been marked as a duplicate of this bug. ***
Still happens with gcc4.5.1.
and 4.7.0
*** Bug 57312 has been marked as a duplicate of this bug. ***
*** Bug 64611 has been marked as a duplicate of this bug. ***
With the current trunk of GCC 7.0 the test cases are rejected as expected (GCC 6 still accepts it). Closing as fixed. $ cat t.C && gcc -O2 -S -Wall -Wextra t.C template <typename> struct A { template <typename> void foo(); }; template <typename T> struct B { template <int> void foo() { A<T>* p; p->foo<int>(); // wrong: should be "p->template foo<int>();" } }; t.C: In member function ‘void B<T>::foo()’: t.C:11:16: error: expected primary-expression before ‘int’ p->foo<int>(); // wrong: should be "p->template foo<int>();" ^~~ t.C:11:16: error: expected ‘;’ before ‘int’