confusing diagnostic for extra qualification on member

For this code:

class MyClass {
public:
MyClass::MyClass();
};

g++ gives:

test.cpp:3: error: extra qualification ‘MyClass::’ on member ‘MyClass’

and comeau gives:

"ComeauTest.c", line 3: error: qualified name is not allowed in member declaration
       MyClass::MyClass();

but clang++ gives:

test.cpp:3:22: error: expected member name or ';' after declaration specifiers
MyClass::MyClass();
~~~~~~~~~~~~~~~~ ^
1 error generated.

which is confusing.

Hi Robert,

Please file a bug in bugzilla, this is serious QoI issue.

-Chris

Robert Reif wrote:

For this code:

class MyClass {
public:
MyClass::MyClass();
};

g++ gives:

test.cpp:3: error: extra qualification ‘MyClass::’ on member ‘MyClass’

and comeau gives:

"ComeauTest.c", line 3: error: qualified name is not allowed in member
declaration
       MyClass::MyClass();

but clang++ gives:

test.cpp:3:22: error: expected member name or ';' after declaration
specifiers
MyClass::MyClass();
~~~~~~~~~~~~~~~~ ^
1 error generated.

which is confusing.

I think this could boil down to the fact that clang does not do the
constructor-name translation in the way comeau and g++ do and the way it
should do. Clang thinks that "MyClass::MyClass" refers to a type (injected
class name), while g++ and comeau do "constructor name translation" (i.e
from the injected class name to a non-type function name, refering to
potentially declared constructors). So clang treats it as a simple-type-
specifier, while comeau/g++ treats it as a declarator-id.

I reported that as http://llvm.org/bugs/show_bug.cgi?id=8263 some time ago
(however, with a different testcase).