tmp/tmpec6figjs/{from.md → to.md}
RENAMED
|
@@ -1,30 +1,29 @@
|
|
| 1 |
### The `typedef` specifier <a id="dcl.typedef">[[dcl.typedef]]</a>
|
| 2 |
|
| 3 |
Declarations containing the *decl-specifier* `typedef` declare
|
| 4 |
-
identifiers that can be used later for naming fundamental
|
| 5 |
-
[[basic.fundamental]]
|
| 6 |
`typedef` specifier shall not be combined in a *decl-specifier-seq* with
|
| 7 |
any other kind of specifier except a *defining-type-specifier*, and it
|
| 8 |
shall not be used in the *decl-specifier-seq* of a
|
| 9 |
-
*parameter-declaration*
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
ill-formed.
|
| 13 |
|
| 14 |
``` bnf
|
| 15 |
typedef-name:
|
| 16 |
identifier
|
|
|
|
| 17 |
```
|
| 18 |
|
| 19 |
-
A name declared with the `typedef` specifier becomes a *typedef-name*.
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
or enum declaration does.
|
| 26 |
|
| 27 |
[*Example 1*:
|
| 28 |
|
| 29 |
After
|
| 30 |
|
|
@@ -55,21 +54,21 @@ particular, it does not define a new type.
|
|
| 55 |
|
| 56 |
``` cpp
|
| 57 |
using handler_t = void (*)(int);
|
| 58 |
extern handler_t ignore;
|
| 59 |
extern void (*ignore)(int); // redeclare ignore
|
| 60 |
-
using cell = pair<void*, cell*>; //
|
| 61 |
```
|
| 62 |
|
| 63 |
— *end example*]
|
| 64 |
|
| 65 |
The *defining-type-specifier-seq* of the *defining-type-id* shall not
|
| 66 |
define a class or enumeration if the *alias-declaration* is the
|
| 67 |
*declaration* of a *template-declaration*.
|
| 68 |
|
| 69 |
In a given non-class scope, a `typedef` specifier can be used to
|
| 70 |
-
|
| 71 |
type to which it already refers.
|
| 72 |
|
| 73 |
[*Example 3*:
|
| 74 |
|
| 75 |
``` cpp
|
|
@@ -79,11 +78,11 @@ typedef int I;
|
|
| 79 |
typedef I I;
|
| 80 |
```
|
| 81 |
|
| 82 |
— *end example*]
|
| 83 |
|
| 84 |
-
In a given class scope, a `typedef` specifier can be used to
|
| 85 |
any *class-name* declared in that scope that is not also a
|
| 86 |
*typedef-name* to refer to the type to which it already refers.
|
| 87 |
|
| 88 |
[*Example 4*:
|
| 89 |
|
|
@@ -95,11 +94,11 @@ struct S {
|
|
| 95 |
};
|
| 96 |
```
|
| 97 |
|
| 98 |
— *end example*]
|
| 99 |
|
| 100 |
-
If a `typedef` specifier is used to
|
| 101 |
that can be referenced using an *elaborated-type-specifier*, the entity
|
| 102 |
can continue to be referenced by an *elaborated-type-specifier* or as an
|
| 103 |
enumeration or class name in an enumeration or class definition
|
| 104 |
respectively.
|
| 105 |
|
|
@@ -114,11 +113,11 @@ int main() {
|
|
| 114 |
struct S { }; // OK
|
| 115 |
```
|
| 116 |
|
| 117 |
— *end example*]
|
| 118 |
|
| 119 |
-
In a given scope, a `typedef` specifier shall not be used to
|
| 120 |
the name of any type declared in that scope to refer to a different
|
| 121 |
type.
|
| 122 |
|
| 123 |
[*Example 6*:
|
| 124 |
|
|
@@ -140,17 +139,19 @@ typedef int complex;
|
|
| 140 |
class complex { ... }; // error: redefinition
|
| 141 |
```
|
| 142 |
|
| 143 |
— *end example*]
|
| 144 |
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
*
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
|
|
|
|
|
|
| 152 |
|
| 153 |
[*Example 8*:
|
| 154 |
|
| 155 |
``` cpp
|
| 156 |
struct S {
|
|
@@ -164,18 +165,42 @@ S a = T(); // OK
|
|
| 164 |
struct T * p; // error
|
| 165 |
```
|
| 166 |
|
| 167 |
— *end example*]
|
| 168 |
|
| 169 |
-
If the typedef declaration defines an unnamed class
|
| 170 |
-
*typedef-name* declared by the declaration to be that
|
| 171 |
-
|
| 172 |
-
|
|
|
|
|
|
|
|
|
|
| 173 |
|
| 174 |
[*Example 9*:
|
| 175 |
|
| 176 |
``` cpp
|
| 177 |
typedef struct { } *ps, S; // S is the class name for linkage purposes
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 178 |
```
|
| 179 |
|
| 180 |
— *end example*]
|
| 181 |
|
|
|
|
| 1 |
### The `typedef` specifier <a id="dcl.typedef">[[dcl.typedef]]</a>
|
| 2 |
|
| 3 |
Declarations containing the *decl-specifier* `typedef` declare
|
| 4 |
+
identifiers that can be used later for naming fundamental
|
| 5 |
+
[[basic.fundamental]] or compound [[basic.compound]] types. The
|
| 6 |
`typedef` specifier shall not be combined in a *decl-specifier-seq* with
|
| 7 |
any other kind of specifier except a *defining-type-specifier*, and it
|
| 8 |
shall not be used in the *decl-specifier-seq* of a
|
| 9 |
+
*parameter-declaration* [[dcl.fct]] nor in the *decl-specifier-seq* of a
|
| 10 |
+
*function-definition* [[dcl.fct.def]]. If a `typedef` specifier appears
|
| 11 |
+
in a declaration without a *declarator*, the program is ill-formed.
|
|
|
|
| 12 |
|
| 13 |
``` bnf
|
| 14 |
typedef-name:
|
| 15 |
identifier
|
| 16 |
+
simple-template-id
|
| 17 |
```
|
| 18 |
|
| 19 |
+
A name declared with the `typedef` specifier becomes a *typedef-name*. A
|
| 20 |
+
*typedef-name* names the type associated with the *identifier*
|
| 21 |
+
[[dcl.decl]] or *simple-template-id* [[temp.pre]]; a *typedef-name* is
|
| 22 |
+
thus a synonym for another type. A *typedef-name* does not introduce a
|
| 23 |
+
new type the way a class declaration [[class.name]] or enum declaration
|
| 24 |
+
[[dcl.enum]] does.
|
|
|
|
| 25 |
|
| 26 |
[*Example 1*:
|
| 27 |
|
| 28 |
After
|
| 29 |
|
|
|
|
| 54 |
|
| 55 |
``` cpp
|
| 56 |
using handler_t = void (*)(int);
|
| 57 |
extern handler_t ignore;
|
| 58 |
extern void (*ignore)(int); // redeclare ignore
|
| 59 |
+
using cell = pair<void*, cell*>; // error
|
| 60 |
```
|
| 61 |
|
| 62 |
— *end example*]
|
| 63 |
|
| 64 |
The *defining-type-specifier-seq* of the *defining-type-id* shall not
|
| 65 |
define a class or enumeration if the *alias-declaration* is the
|
| 66 |
*declaration* of a *template-declaration*.
|
| 67 |
|
| 68 |
In a given non-class scope, a `typedef` specifier can be used to
|
| 69 |
+
redeclare the name of any type declared in that scope to refer to the
|
| 70 |
type to which it already refers.
|
| 71 |
|
| 72 |
[*Example 3*:
|
| 73 |
|
| 74 |
``` cpp
|
|
|
|
| 78 |
typedef I I;
|
| 79 |
```
|
| 80 |
|
| 81 |
— *end example*]
|
| 82 |
|
| 83 |
+
In a given class scope, a `typedef` specifier can be used to redeclare
|
| 84 |
any *class-name* declared in that scope that is not also a
|
| 85 |
*typedef-name* to refer to the type to which it already refers.
|
| 86 |
|
| 87 |
[*Example 4*:
|
| 88 |
|
|
|
|
| 94 |
};
|
| 95 |
```
|
| 96 |
|
| 97 |
— *end example*]
|
| 98 |
|
| 99 |
+
If a `typedef` specifier is used to redeclare in a given scope an entity
|
| 100 |
that can be referenced using an *elaborated-type-specifier*, the entity
|
| 101 |
can continue to be referenced by an *elaborated-type-specifier* or as an
|
| 102 |
enumeration or class name in an enumeration or class definition
|
| 103 |
respectively.
|
| 104 |
|
|
|
|
| 113 |
struct S { }; // OK
|
| 114 |
```
|
| 115 |
|
| 116 |
— *end example*]
|
| 117 |
|
| 118 |
+
In a given scope, a `typedef` specifier shall not be used to redeclare
|
| 119 |
the name of any type declared in that scope to refer to a different
|
| 120 |
type.
|
| 121 |
|
| 122 |
[*Example 6*:
|
| 123 |
|
|
|
|
| 139 |
class complex { ... }; // error: redefinition
|
| 140 |
```
|
| 141 |
|
| 142 |
— *end example*]
|
| 143 |
|
| 144 |
+
A *simple-template-id* is only a *typedef-name* if its *template-name*
|
| 145 |
+
names an alias template or a template *template-parameter*.
|
| 146 |
+
|
| 147 |
+
[*Note 1*: A *simple-template-id* that names a class template
|
| 148 |
+
specialization is a *class-name* [[class.name]]. If a *typedef-name* is
|
| 149 |
+
used to identify the subject of an *elaborated-type-specifier*
|
| 150 |
+
[[dcl.type.elab]], a class definition [[class]], a constructor
|
| 151 |
+
declaration [[class.ctor]], or a destructor declaration [[class.dtor]],
|
| 152 |
+
the program is ill-formed. — *end note*]
|
| 153 |
|
| 154 |
[*Example 8*:
|
| 155 |
|
| 156 |
``` cpp
|
| 157 |
struct S {
|
|
|
|
| 165 |
struct T * p; // error
|
| 166 |
```
|
| 167 |
|
| 168 |
— *end example*]
|
| 169 |
|
| 170 |
+
If the typedef declaration defines an unnamed class or enumeration, the
|
| 171 |
+
first *typedef-name* declared by the declaration to be that type is used
|
| 172 |
+
to denote the type for linkage purposes only [[basic.link]].
|
| 173 |
+
|
| 174 |
+
[*Note 2*: A typedef declaration involving a *lambda-expression* does
|
| 175 |
+
not itself define the associated closure type, and so the closure type
|
| 176 |
+
is not given a name for linkage purposes. — *end note*]
|
| 177 |
|
| 178 |
[*Example 9*:
|
| 179 |
|
| 180 |
``` cpp
|
| 181 |
typedef struct { } *ps, S; // S is the class name for linkage purposes
|
| 182 |
+
typedef decltype([]{}) C; // the closure type has no name for linkage purposes
|
| 183 |
+
```
|
| 184 |
+
|
| 185 |
+
— *end example*]
|
| 186 |
+
|
| 187 |
+
An unnamed class with a typedef name for linkage purposes shall not
|
| 188 |
+
|
| 189 |
+
- declare any members other than non-static data members, member
|
| 190 |
+
enumerations, or member classes,
|
| 191 |
+
- have any base classes or default member initializers, or
|
| 192 |
+
- contain a *lambda-expression*,
|
| 193 |
+
|
| 194 |
+
and all member classes shall also satisfy these requirements
|
| 195 |
+
(recursively).
|
| 196 |
+
|
| 197 |
+
[*Example 10*:
|
| 198 |
+
|
| 199 |
+
``` cpp
|
| 200 |
+
typedef struct {
|
| 201 |
+
int f() {}
|
| 202 |
+
} X; // error: struct with typedef name for linkage has member functions
|
| 203 |
```
|
| 204 |
|
| 205 |
— *end example*]
|
| 206 |
|