[dcl.type.elab] (original) (raw)
9 Declarations [dcl.dcl]
9.2 Specifiers [dcl.spec]
9.2.9 Type specifiers [dcl.type]
9.2.9.4 Elaborated type specifiers [dcl.type.elab]
An attribute-specifier-seq shall not appear in an elaborated-type-specifierunless the latter is the sole constituent of a declaration.
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]), an explicit instantiation ([temp.explicit]) or it has one of the following forms:
[Note 2:
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 allowed ([class.friend]).
— _end note_]
The class-key or enum keyword present in theelaborated-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_]