标准中的哪个地方说成员别名声明可以像静态成员一样使用?

Where in the Standard does it say that a member alias-declaration can be used as if it was a static member?

考虑以下片段:

#include <iostream>
struct A { int i; using Int = int; };

int main()
{
    std::cout << sizeof(A::Int) << '\n';
}

clang和GCC中编译执行正常。我知道这看起来很明显,但我在标准 (C++14) 中找不到任何支持在 main().

中引用 A::Int 的内容

这只是您正常的合格查询。来自 [basic.lookup.qual]:

The name of a class or namespace member or enumerator can be referred to after the :: scope resolution operator (5.1) applied to a nested-name-specifier that denotes its class, namespace, or enumeration.

然后来自[class.qual]:

If the nested-name-specifier of a qualified-id nominates a class, the name specified after the nested-namespecifier is looked up in the scope of the class (10.2), except for the cases listed below. The name shall represent one or more members of that class or of one of its base classes (Clause 10). [ Note: A class member can be referred to using a qualified-id at any point in its potential scope (3.3.7). —end note ] The exceptions to the name lookup rule above are the following:

  • a destructor name [...]
  • a conversion-type-id of a conversion-function-id [...]
  • the names in a template-argument of a template-id [...]
  • the lookup for a name specified in a using-declaration [...]

您示例中的 nested-name-specifierA,这是一个 class。 None 这些例外情况适用。所以我们只在 class.

的范围内查找名称 Int

来自[dcl.typedef]:

A name declared with the typedef specifier becomes a typedef-name. Within the scope of its declaration, a typedef-name is syntactically equivalent to a keyword and names the type associated with the identifier in the way described in Clause 8. A typedef-name is thus a synonym for another type.
[...]
A typedef-name can also be introduced by an alias-declaration. The identifier following the using keyword becomes a typedef-name and the optional attribute-specifier-seq following the identifier appertains to that typedef-name. It has the same semantics as if it were introduced by the typedef specifier.

所以你的alias-declaration把名字Int引入到A的范围内,这是根据我刚才列举的符合条件的查找规则找到的.