[cfe-dev] confusing diagnostic for extra qualification on member

Johannes Schaub (litb) schaub.johannes at googlemail.com
Tue Feb 1 16:10:44 PST 2011

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).

More information about the cfe-dev mailing list