[dcl.type.elab] (original) (raw)
9 Declarations [dcl]
9.2 Specifiers [dcl.spec]
9.2.9 Type specifiers [dcl.type]
9.2.9.5 Elaborated type specifiers [dcl.type.elab]
If an elaborated-type-specifier is the sole constituent of a declaration, the declaration is ill-formed unless it is an explicit specialization ([temp.expl.spec]), a partial specialization ([temp.spec.partial]), an explicit instantiation ([temp.explicit]), or it has one of the following forms:
The target scope of E is the nearest enclosing namespace or block scope.
A friend-type-specifierthat is an elaborated-type-specifiershall have one of the following forms:
Any unqualified lookup for the identifier (in the first case) does not consider scopes that contain the nearest enclosing namespace or block scope; no name is bound.
[Note 1:
A using-directive in the target scope is ignored if it refers to a namespace not contained by that scope.
— _end note_]
[Note 2:
An elaborated-type-specifier can be used to refer to a previously declared class-name or enum-nameeven if the name has been hidden by a non-type declaration.
— _end note_]
[Note 3:
This implies that, within a class template with a templatetype-parameter T, the declarationfriend class T;is ill-formed.
However, the similar declaration friend T; is well-formed ([class.friend]).
— _end note_]
The class-key or enum keyword present in anelaborated-type-specifier shall agree in kind with the declaration to which the name in theelaborated-type-specifier refers.
This rule also applies to the form of elaborated-type-specifier that declares aclass-name or friend class since it can be construed as referring to the definition of the class.
Thus, in anyelaborated-type-specifier, the enum keyword shall be used to refer to an enumeration ([dcl.enum]), the union class-key shall be used to refer to a union ([class.union]), and either the class or struct class-key shall be used to refer to a non-union class ([class.pre]).
[Example 1: enum class E { a, b };enum E x = E::a; struct S { } s;class S* p = &s; — _end example_]