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++/16234] New: Bad diagnostic


template<typename T> struct A {
    template<typename U> void Foo(){} };
template<typename V>struct B {
    void Bar(V* v) {
        v->template Foo<int>();
        v->Foo<int>();
        }
    };
int main() {
    A<bool> a;
    B<A<bool> > b;
    b.Bar(&a);
    }

gets you:

~/ootbc/common/test/src$ g++ foo.cc
foo.cc: In member function `void B<V>::Bar(V*)':
foo.cc:6: error: expected primary-expression before "int"
foo.cc:6: error: expected `;' before "int"

The actual problem is the missing explicit "template" qualification. Surely the compiler can recognize "<int>" as a template argument list in this case for purposes of the diagnostic. There is an eroror here - the rules do require a diagnostic - but the compiler could be a lot more graceful about what it says when it doesn't get the required qualifier.


I grant that templates with data arguments cannot be as easily recognized in such a context. In:

template<typename T> struct A {
    template<int I> void Foo(){} };
template<typename V>struct B {
    void Bar(V* v) {
        v->template Foo<int>();
        v->Foo<5>();
        }
    };
int main() {
    A<bool> a;
    B<A<bool> > b;
    b.Bar(&a);
    }

ot is probably too tough to figure out what is wrong (operator <(void(*)(), int)???, although that is very unlikely and would be syntactically wrong here even if the operator existed). Just assuming that "anyTemplateFunc<" is the start of a template invocation would give the best diagnostic most likely, and the compiler can complain that the assumption is not permitted by the lanhuage. One of the fameous "ISO C++ requires that the invocation 'Foo<int>' be explicitly qualified as 'template Foo<int>'" messages, maybe?

Ivan

-- 
           Summary: Bad diagnostic
           Product: gcc
           Version: 3.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: igodard at pacbell dot net
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16234


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