[cfe-commits] PATCH: Add a fixit hint to the error for an injected-class-name where one can't occur

Johannes Schaub schaub.johannes at googlemail.com
Sun Jul 31 04:57:05 PDT 2011


Chandler Carruth wrote:

> Specifically, Clang currently errors on the following code:
> 
> struct X {};
> X::X x;
> 
> As the type specifier 'X::X' isn't a valid use of the injected class name,
> it instead names the constructor. The code in question performs error
> recovery as if this *did* name the type already, but doesn't suggest a
> fixit hint to make it actually name the type. This patch adds that fixit
> hint.
> 
> I have a tiny reservation here that there might be cases where the
> suggestion change to the code doesn't actually match the recovery's
> interpretation of 'X::X', specifically a context wherhe 'X' alone wouldn't
> name a class type, but 'X::X' would if it were allowed. I don't think any
> such case exists, but it might, so I wanted to run it by folks first.
> 

Consider:

struct X { };
void X() { }

X x; // error: X is a function
X::X x;

If X::X would not name the constructor, it would be the injected class name 
of X (prior to a "::", function names are ignored). 

The fix-it could instead be

    struct X::X





More information about the cfe-commits mailing list