This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/11814] New: Code with missing "template" keyword wrongly accepted


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]