From Jason Turner

[dcl.typedef]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpe0ex9s5v/{from.md → to.md} +16 -91
tmp/tmpe0ex9s5v/{from.md → to.md} RENAMED
@@ -42,118 +42,43 @@ are all correct declarations; the type of `distance` is `int` and that
42
  of `metricp` is “pointer to `int`”.
43
 
44
  — *end example*]
45
 
46
  A *typedef-name* can also be introduced by an *alias-declaration*. The
47
- *identifier* following the `using` keyword becomes a *typedef-name* and
48
- the optional *attribute-specifier-seq* following the *identifier*
49
- appertains to that *typedef-name*. Such a *typedef-name* has the same
50
- semantics as if it were introduced by the `typedef` specifier. In
51
- particular, it does not define a new type.
52
 
53
  [*Example 2*:
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
75
- typedef struct s { ... } s;
76
- typedef int I;
77
- typedef int I;
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
-
89
- ``` cpp
90
- struct S {
91
- typedef struct A { } A; // OK
92
- typedef struct B B; // OK
93
- typedef A A; // error
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
-
105
- [*Example 5*:
106
-
107
- ``` cpp
108
- struct S;
109
- typedef struct S S;
110
- int main() {
111
- struct S* p; // OK
112
- }
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
-
124
- ``` cpp
125
- class complex { ... };
126
- typedef int complex; // error: redefinition
127
- ```
128
-
129
- — *end example*]
130
-
131
- Similarly, in a given scope, a class or enumeration shall not be
132
- declared with the same name as a *typedef-name* that is declared in that
133
- scope and refers to a type other than the class or enumeration itself.
134
-
135
- [*Example 7*:
136
-
137
- ``` cpp
138
- typedef int complex;
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 {
158
  S();
159
  ~S();
@@ -165,23 +90,23 @@ S a = T(); // OK
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
@@ -192,11 +117,11 @@ An unnamed class with a typedef name for linkage purposes shall not
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
 
42
  of `metricp` is “pointer to `int`”.
43
 
44
  — *end example*]
45
 
46
  A *typedef-name* can also be introduced by an *alias-declaration*. The
47
+ *identifier* following the `using` keyword is not looked up; it becomes
48
+ a *typedef-name* and the optional *attribute-specifier-seq* following
49
+ the *identifier* appertains to that *typedef-name*. Such a
50
+ *typedef-name* has the same semantics as if it were introduced by the
51
+ `typedef` specifier. In particular, it does not define a new type.
52
 
53
  [*Example 2*:
54
 
55
  ``` cpp
56
  using handler_t = void (*)(int);
57
  extern handler_t ignore;
58
  extern void (*ignore)(int); // redeclare ignore
59
+ template<class T> struct P { };
60
+ using cell = P<cell*>; // error: cell not found[basic.scope.pdecl]
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
  A *simple-template-id* is only a *typedef-name* if its *template-name*
70
  names an alias template or a template *template-parameter*.
71
 
72
  [*Note 1*: A *simple-template-id* that names a class template
73
  specialization is a *class-name* [[class.name]]. If a *typedef-name* is
74
  used to identify the subject of an *elaborated-type-specifier*
75
  [[dcl.type.elab]], a class definition [[class]], a constructor
76
  declaration [[class.ctor]], or a destructor declaration [[class.dtor]],
77
  the program is ill-formed. — *end note*]
78
 
79
+ [*Example 3*:
80
 
81
  ``` cpp
82
  struct S {
83
  S();
84
  ~S();
 
90
  struct T * p; // error
91
  ```
92
 
93
  — *end example*]
94
 
95
+ An unnamed class or enumeration C defined in a typedef declaration has
96
+ the first *typedef-name* declared by the declaration to be of type C as
97
+ its *typedef name for linkage purposes* [[basic.link]].
98
 
99
  [*Note 2*: A typedef declaration involving a *lambda-expression* does
100
  not itself define the associated closure type, and so the closure type
101
+ is not given a typedef name for linkage purposes. — *end note*]
102
 
103
+ [*Example 4*:
104
 
105
  ``` cpp
106
+ typedef struct { } *ps, S; // S is the typedef name for linkage purposes
107
+ typedef decltype([]{}) C; // the closure type has no typedef name for linkage purposes
108
  ```
109
 
110
  — *end example*]
111
 
112
  An unnamed class with a typedef name for linkage purposes shall not
 
117
  - contain a *lambda-expression*,
118
 
119
  and all member classes shall also satisfy these requirements
120
  (recursively).
121
 
122
+ [*Example 5*:
123
 
124
  ``` cpp
125
  typedef struct {
126
  int f() {}
127
  } X; // error: struct with typedef name for linkage has member functions