From Jason Turner

[dcl.typedef]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpto37hevg/{from.md → to.md} +63 -18
tmp/tmpto37hevg/{from.md → to.md} RENAMED
@@ -2,14 +2,16 @@
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 *type-specifier,* and it shall not
8
- be used in the *decl-specifier-seq* of a *parameter-declaration* (
9
- [[dcl.fct]]) nor in the *decl-specifier-seq* of a
10
- *function-definition* ([[dcl.fct.def]]).
 
 
11
 
12
  ``` bnf
13
  typedef-name:
14
  identifier
15
  ```
@@ -18,11 +20,15 @@ A name declared with the `typedef` specifier becomes a *typedef-name*.
18
  Within the scope of its declaration, a *typedef-name* is syntactically
19
  equivalent to a keyword and names the type associated with the
20
  identifier in the way described in Clause  [[dcl.decl]]. A
21
  *typedef-name* is thus a synonym for another type. A *typedef-name* does
22
  not introduce a new type the way a class declaration ([[class.name]])
23
- or enum declaration does. after
 
 
 
 
24
 
25
  ``` cpp
26
  typedef int MILES, *KLICKSP;
27
  ```
28
 
@@ -32,88 +38,121 @@ the constructions
32
  MILES distance;
33
  extern KLICKSP metricp;
34
  ```
35
 
36
  are all correct declarations; the type of `distance` is `int` and that
37
- of `metricp` is “pointer to `int`.
 
 
38
 
39
  A *typedef-name* can also be introduced by an *alias-declaration*. The
40
  *identifier* following the `using` keyword becomes a *typedef-name* and
41
  the optional *attribute-specifier-seq* following the *identifier*
42
- appertains to that *typedef-name*. It has the same semantics as if it
43
- were introduced by the `typedef` specifier. In particular, it does not
44
- define a new type and it shall not appear in the *type-id*.
 
 
45
 
46
  ``` cpp
47
  using handler_t = void (*)(int);
48
  extern handler_t ignore;
49
  extern void (*ignore)(int); // redeclare ignore
50
  using cell = pair<void*, cell*>; // ill-formed
51
  ```
52
 
 
 
 
 
 
 
53
  In a given non-class scope, a `typedef` specifier can be used to
54
  redefine the name of any type declared in that scope to refer to the
55
  type to which it already refers.
56
 
 
 
57
  ``` cpp
58
- typedef struct s { /* ... */ } s;
59
  typedef int I;
60
  typedef int I;
61
  typedef I I;
62
  ```
63
 
 
 
64
  In a given class scope, a `typedef` specifier can be used to redefine
65
  any *class-name* declared in that scope that is not also a
66
  *typedef-name* to refer to the type to which it already refers.
67
 
 
 
68
  ``` cpp
69
  struct S {
70
  typedef struct A { } A; // OK
71
  typedef struct B B; // OK
72
  typedef A A; // error
73
  };
74
  ```
75
 
 
 
76
  If a `typedef` specifier is used to redefine in a given scope an entity
77
  that can be referenced using an *elaborated-type-specifier*, the entity
78
  can continue to be referenced by an *elaborated-type-specifier* or as an
79
  enumeration or class name in an enumeration or class definition
80
  respectively.
81
 
 
 
82
  ``` cpp
83
  struct S;
84
  typedef struct S S;
85
  int main() {
86
  struct S* p; // OK
87
  }
88
  struct S { }; // OK
89
  ```
90
 
 
 
91
  In a given scope, a `typedef` specifier shall not be used to redefine
92
  the name of any type declared in that scope to refer to a different
93
  type.
94
 
 
 
95
  ``` cpp
96
- class complex { /* ... */ };
97
  typedef int complex; // error: redefinition
98
  ```
99
 
 
 
100
  Similarly, in a given scope, a class or enumeration shall not be
101
  declared with the same name as a *typedef-name* that is declared in that
102
  scope and refers to a type other than the class or enumeration itself.
103
 
 
 
104
  ``` cpp
105
  typedef int complex;
106
- class complex { /* ... */ }; // error: redefinition
107
  ```
108
 
109
- A *typedef-name* that names a class type, or a cv-qualified version
110
- thereof, is also a *class-name* ([[class.name]]). If a *typedef-name*
111
- is used to identify the subject of an *elaborated-type-specifier* (
112
- [[dcl.type.elab]]), a class definition (Clause  [[class]]), a
113
- constructor declaration ([[class.ctor]]), or a destructor declaration (
114
- [[class.dtor]]), the program is ill-formed.
 
 
 
 
 
115
 
116
  ``` cpp
117
  struct S {
118
  S();
119
  ~S();
@@ -123,14 +162,20 @@ typedef struct S T;
123
 
124
  S a = T(); // OK
125
  struct T * p; // error
126
  ```
127
 
 
 
128
  If the typedef declaration defines an unnamed class (or enum), the first
129
  *typedef-name* declared by the declaration to be that class type (or
130
  enum type) is used to denote the class type (or enum type) for linkage
131
  purposes only ([[basic.link]]).
132
 
 
 
133
  ``` cpp
134
  typedef struct { } *ps, S; // S is the class name for linkage purposes
135
  ```
136
 
 
 
 
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*
10
+ of a *function-definition* ([[dcl.fct.def]]). If a `typedef` specifier
11
+ appears in a declaration without a *declarator*, the program is
12
+ ill-formed.
13
 
14
  ``` bnf
15
  typedef-name:
16
  identifier
17
  ```
 
20
  Within the scope of its declaration, a *typedef-name* is syntactically
21
  equivalent to a keyword and names the type associated with the
22
  identifier in the way described in Clause  [[dcl.decl]]. A
23
  *typedef-name* is thus a synonym for another type. A *typedef-name* does
24
  not introduce a new type the way a class declaration ([[class.name]])
25
+ or enum declaration does.
26
+
27
+ [*Example 1*:
28
+
29
+ After
30
 
31
  ``` cpp
32
  typedef int MILES, *KLICKSP;
33
  ```
34
 
 
38
  MILES distance;
39
  extern KLICKSP metricp;
40
  ```
41
 
42
  are all correct declarations; the type of `distance` is `int` and that
43
+ of `metricp` is “pointer to `int`”.
44
+
45
+ — *end example*]
46
 
47
  A *typedef-name* can also be introduced by an *alias-declaration*. The
48
  *identifier* following the `using` keyword becomes a *typedef-name* and
49
  the optional *attribute-specifier-seq* following the *identifier*
50
+ appertains to that *typedef-name*. Such a *typedef-name* has the same
51
+ semantics as if it were introduced by the `typedef` specifier. In
52
+ particular, it does not define a new type.
53
+
54
+ [*Example 2*:
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*>; // ill-formed
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
  redefine the name of any type declared in that scope to refer to the
71
  type to which it already refers.
72
 
73
+ [*Example 3*:
74
+
75
  ``` cpp
76
+ typedef struct s { ... } s;
77
  typedef int I;
78
  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 redefine
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
+
90
  ``` cpp
91
  struct S {
92
  typedef struct A { } A; // OK
93
  typedef struct B B; // OK
94
  typedef A A; // error
95
  };
96
  ```
97
 
98
+ — *end example*]
99
+
100
  If a `typedef` specifier is used to redefine in a given scope an entity
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
 
106
+ [*Example 5*:
107
+
108
  ``` cpp
109
  struct S;
110
  typedef struct S S;
111
  int main() {
112
  struct S* p; // OK
113
  }
114
  struct S { }; // OK
115
  ```
116
 
117
+ — *end example*]
118
+
119
  In a given scope, a `typedef` specifier shall not be used to redefine
120
  the name of any type declared in that scope to refer to a different
121
  type.
122
 
123
+ [*Example 6*:
124
+
125
  ``` cpp
126
+ class complex { ... };
127
  typedef int complex; // error: redefinition
128
  ```
129
 
130
+ — *end example*]
131
+
132
  Similarly, in a given scope, a class or enumeration shall not be
133
  declared with the same name as a *typedef-name* that is declared in that
134
  scope and refers to a type other than the class or enumeration itself.
135
 
136
+ [*Example 7*:
137
+
138
  ``` cpp
139
  typedef int complex;
140
+ class complex { ... }; // error: redefinition
141
  ```
142
 
143
+ *end example*]
144
+
145
+ [*Note 1*: A *typedef-name* that names a class type, or a cv-qualified
146
+ version thereof, is also a *class-name* ([[class.name]]). If a
147
+ *typedef-name* is used to identify the subject of an
148
+ *elaborated-type-specifier* ([[dcl.type.elab]]), a class definition
149
+ (Clause  [[class]]), a constructor declaration ([[class.ctor]]), or a
150
+ destructor declaration ([[class.dtor]]), the program is
151
+ ill-formed. — *end note*]
152
+
153
+ [*Example 8*:
154
 
155
  ``` cpp
156
  struct S {
157
  S();
158
  ~S();
 
162
 
163
  S a = T(); // OK
164
  struct T * p; // error
165
  ```
166
 
167
+ — *end example*]
168
+
169
  If the typedef declaration defines an unnamed class (or enum), the first
170
  *typedef-name* declared by the declaration to be that class type (or
171
  enum type) is used to denote the class type (or enum type) for linkage
172
  purposes only ([[basic.link]]).
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
+