Consider this code:
struct foo{};
int main() {
foo::foo a;
}
I would expect this to be well-formed, declaring a variable of type foo
by the rule in [class]/2 (N4140, emphasis mine):
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. For purposes of access checking, the injected-class-name is treated as if it were a public member name.
clang 3.6.0
agrees with me, compiling the above code with no applicable warnings with -Wall -pedantic
.
gcc 5.2.0
disagrees, providing the following error message:
main.cpp: In function 'int main()':
main.cpp:5:5: error: 'foo::foo' names the constructor, not the type
foo::foo a;
The above holds no matter how deep the nesting of injected class names, e.g. foo::foo::foo::foo
.
Is there a rule which forces that construct to be interpreted as a constructor in that context, or is this agcc
bug? Or am I interpreting the standards quote incorrectly?