在标准 (C++14) 的哪个地方说以下两个声明是等价的?

Where in the Standard (C++14) does it say that the following two declarations are equivalent?

struct A{};
int A;
struct A a;
struct A::A b;

上面的最后两个声明 equivalent.They 都声明了类型 A 的对象。我可以在标准中的什么地方找到或推导出这个?

[class]/2:

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.

A::A::A::A 也指代 A。在某些情况下,A::A 可以命名构造函数,尽管 - [class.qual]/2 涵盖了这一点,它的注释甚至解决了你的例子:

In a lookup in which function names are not ignored33 and the nested-name-specifier nominates a class C

  • if the name specified after the nested-name-specifier, when looked up in C, is the injected-class-name of C (Clause 9), or
  • in a using-declaration (7.3.3) that is a member-declaration, if the name specified after the nested-name- specifier is the same as the identifier or the simple-template-id’s template-name in the last component of the nested-name-specifier,

the name is instead considered to name the constructor of class C. [ Note: For example, the constructor is not an acceptable lookup result in an elaborated-type-specifier so the constructor would not be used in place of the injected-class-name. — end note ]


33) Lookups in which function names are ignored include names appearing in a nested-name-specifier, an elaborated-type- specifier, or a base-specifier.

所以在这样的语句中

A::A a;

函数名称在查找 A::A 而不是 被忽略,因此代码格式错误,因为 A::A 引用了构造函数。然而,在

struct B : A::A {};
struct A::A a;

一切都很好,因为函数名称在基本说明符和详细类型说明符中被忽略。