[dcl.typedef] (original) (raw)
9 Declarations [dcl]
9.2 Specifiers [dcl.spec]
9.2.4 The typedef specifier [dcl.typedef]
If a typedef specifier appears in a declaration without a declarator, the program is ill-formed.
A name declared with the typedef specifier becomes atypedef-name.
Atypedef-name does not introduce a new type the way a class declaration ([class.name]) or enum declaration ([dcl.enum]) does.
[Example 1:
Aftertypedef int MILES, *KLICKSP;the constructionsMILES distance;extern KLICKSP metricp;are all correct declarations; the type of distance isint and that of metricp is “pointer to int”.
— _end example_]
Such a typedef-name has the same semantics as if it were introduced by the typedef specifier.
In particular, it does not define a new type.
[Example 2: using handler_t = void (*)(int);extern handler_t ignore;extern void (*ignore)(int); template<class T> struct P { };using cell = P<cell*>; — _end example_]
[Example 3: struct S { S();~S();};typedef struct S T; S a = T(); struct T * p; — _end example_]
An unnamed class or enumeration C defined in a typedef declaration has the first typedef-namedeclared by the declaration to be of type Cas its typedef name for linkage purposes ([basic.link]).
[Note 2:
A typedef declaration involving a lambda-expressiondoes not itself define the associated closure type, and so the closure type is not given a typedef name for linkage purposes.
— _end note_]
[Example 4: typedef struct { } *ps, S; typedef decltype([]{}) C; — _end example_]
An unnamed class with a typedef name for linkage purposes shall not
- declare any members other than non-static data members, member enumerations, or member classes,
- have any base classes or default member initializers, or
- contain a lambda-expression,
and all member classes shall also satisfy these requirements (recursively).
[Example 5: typedef struct { int f() {} } X; — _end example_]