Following code snippet seems incorrect, but clang handles it without error. class CFoo { public: CFoo() {}; ~CFoo() {}; }; int main() { CFoo::CFoo::CFoo::CFoo::CFoo* pFoo = new CFoo(); }
Clang is correct. The inner ::CFoo is the injected class name.
Could you explain about this behavior? GCC handles it as an error.
Looks like GCC implements the resolution of core issue 1310, under which this is ill-formed. For some lookups, this rule applies: C++ [class]p2: "A class-name is inserted into the scope in which it is declared immediately after the class-name is seen. The class-name is also inserted into the scope of the class itself; this is known as the injected-class-name." However, under core issue 1310, this only applies in the rarer case of a lookup which ignores function names. So the 'CFoo::CFoo::' finds the injected-class-name, but the final '::CFoo' is a constructor name.
*** Bug 15860 has been marked as a duplicate of this bug. ***
*** Bug 19276 has been marked as a duplicate of this bug. ***
*** This bug has been marked as a duplicate of bug 13403 ***