[Bug c++/11814] New: Code with missing "template" keyword wrongly accepted
reichelt at gcc dot gnu dot org
gcc-bugzilla@gcc.gnu.org
Tue Aug 5 23:09:00 GMT 2003
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11814
Summary: Code with missing "template" keyword wrongly accepted
Product: gcc
Version: 3.4
Status: UNCONFIRMED
Keywords: accepts-invalid
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: reichelt at gcc dot gnu dot org
CC: gcc-bugs at gcc dot gnu dot org
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.
More information about the Gcc-bugs
mailing list