From Jason Turner

[enum]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp1kys2_sb/{from.md → to.md} +47 -60
tmp/tmp1kys2_sb/{from.md → to.md} RENAMED
@@ -85,11 +85,13 @@ struct S {
85
 
86
  — *end example*]
87
 
88
  — *end note*]
89
 
90
- If the *enum-head-name* of an *opaque-enum-declaration* contains a
 
 
91
  *nested-name-specifier*, the declaration shall be an explicit
92
  specialization [[temp.expl.spec]].
93
 
94
  The enumeration type declared with an *enum-key* of only `enum` is an
95
  *unscoped enumeration*, and its *enumerator*s are *unscoped
@@ -100,16 +102,18 @@ enumerators*. The optional *enum-head-name* shall not be omitted in the
100
  declaration of a scoped enumeration. The *type-specifier-seq* of an
101
  *enum-base* shall name an integral type; any cv-qualification is
102
  ignored. An *opaque-enum-declaration* declaring an unscoped enumeration
103
  shall not omit the *enum-base*. The identifiers in an *enumerator-list*
104
  are declared as constants, and can appear wherever constants are
105
- required. An *enumerator-definition* with `=` gives the associated
106
- *enumerator* the value indicated by the *constant-expression*. If the
107
- first *enumerator* has no *initializer*, the value of the corresponding
108
- constant is zero. An *enumerator-definition* without an *initializer*
109
- gives the *enumerator* the value obtained by increasing the value of the
110
- previous *enumerator* by one.
 
 
111
 
112
  [*Example 2*:
113
 
114
  ``` cpp
115
  enum { a, b, c=0 };
@@ -135,19 +139,17 @@ can be provided in a later redeclaration with an
135
  A scoped enumeration shall not be later redeclared as unscoped or with a
136
  different underlying type. An unscoped enumeration shall not be later
137
  redeclared as scoped and each redeclaration shall include an *enum-base*
138
  specifying the same underlying type as in the original declaration.
139
 
140
- If an *enum-head-name* contains a *nested-name-specifier*, it shall not
141
- begin with a *decltype-specifier* and the enclosing *enum-specifier* or
142
- *opaque-enum-declaration* shall refer to an enumeration that was
143
- previously declared directly in the class or namespace to which the
144
- *nested-name-specifier* refers, or in an element of the inline namespace
145
- set [[namespace.def]] of that namespace (i.e., neither inherited nor
146
- introduced by a *using-declaration*), and the *enum-specifier* or
147
- *opaque-enum-declaration* shall appear in a namespace enclosing the
148
- previous declaration.
149
 
150
  Each enumeration defines a type that is different from all other types.
151
  Each enumeration also has an *underlying type*. The underlying type can
152
  be explicitly specified using an *enum-base*. For a scoped enumeration
153
  type, the underlying type is `int` if it is not explicitly specified. In
@@ -171,16 +173,15 @@ the closing brace is determined as follows:
171
  preceding enumerator unless the incremented value is not representable
172
  in that type, in which case the type is an unspecified integral type
173
  sufficient to contain the incremented value. If no such type exists,
174
  the program is ill-formed.
175
 
176
- An enumeration whose underlying type is fixed is an incomplete type from
177
- its point of declaration [[basic.scope.pdecl]] to immediately after its
178
- *enum-base* (if any), at which point it becomes a complete type. An
179
- enumeration whose underlying type is not fixed is an incomplete type
180
- from its point of declaration to immediately after the closing `}` of
181
- its *enum-specifier*, at which point it becomes a complete type.
182
 
183
  For an enumeration whose underlying type is not fixed, the underlying
184
  type is an integral type that can represent all the enumerator values
185
  defined in the enumeration. If no integral type can represent all the
186
  enumerator values, the enumeration is ill-formed. It is
@@ -198,10 +199,15 @@ represented. The width of the smallest bit-field large enough to hold
198
  all the values of the enumeration type is M. It is possible to define an
199
  enumeration that has values not defined by any of its enumerators. If
200
  the *enumerator-list* is empty, the values of the enumeration are as if
201
  the enumeration had a single enumerator with value 0.[^9]
202
 
 
 
 
 
 
203
  Two enumeration types are *layout-compatible enumerations* if they have
204
  the same underlying type.
205
 
206
  The value of an enumerator or an object of an unscoped enumeration type
207
  is converted to an integer by integral promotion [[conv.prom]].
@@ -222,11 +228,11 @@ type. The possible values of an object of type `color` are `red`,
222
  values `0`, `1`, `20`, and `21`. Since enumerations are distinct types,
223
  objects of type `color` can be assigned only values of type `color`.
224
 
225
  ``` cpp
226
  color c = 1; // error: type mismatch, no conversion from int to color
227
- int i = yellow; // OK: yellow converted to integral value 1, integral promotion
228
  ```
229
 
230
  Note that this implicit `enum` to `int` conversion is not provided for a
231
  scoped enumeration:
232
 
@@ -237,19 +243,17 @@ Col y = Col::red;
237
  if (y) { } // error: no Col to bool conversion
238
  ```
239
 
240
  — *end example*]
241
 
242
- Each *enum-name* and each unscoped *enumerator* is declared in the scope
243
- that immediately contains the *enum-specifier*. Each scoped *enumerator*
244
- is declared in the scope of the enumeration. An unnamed enumeration that
245
  does not have a typedef name for linkage purposes [[dcl.typedef]] and
246
  that has a first enumerator is denoted, for linkage purposes
247
  [[basic.link]], by its underlying type and its first enumerator; such an
248
  enumeration is said to have an enumerator as a name for linkage
249
- purposes. These names obey the scope rules defined for all names in 
250
- [[basic.scope]] and  [[basic.lookup]].
251
 
252
  [*Note 3*: Each unnamed enumeration with no enumerators is a distinct
253
  type. — *end note*]
254
 
255
  [*Example 4*:
@@ -272,52 +276,35 @@ void h() {
272
  }
273
  ```
274
 
275
  — *end example*]
276
 
277
- An enumerator declared in class scope can be referred to using the class
278
- member access operators (`::`, `.` (dot) and `->` (arrow)), see 
279
- [[expr.ref]].
280
-
281
- [*Example 5*:
282
-
283
- ``` cpp
284
- struct X {
285
- enum direction { left='l', right='r' };
286
- int f(int i) { return i==left ? 0 : i==right ? 1 : 2; }
287
- };
288
-
289
- void g(X* p) {
290
- direction d; // error: direction not in scope
291
- int i;
292
- i = p->f(left); // error: left not in scope
293
- i = p->f(X::right); // OK
294
- i = p->f(p->left); // OK
295
- // ...
296
- }
297
- ```
298
-
299
- — *end example*]
300
-
301
  ### The `using enum` declaration <a id="enum.udecl">[[enum.udecl]]</a>
302
 
303
  ``` bnf
304
  using-enum-declaration:
305
- 'using' elaborated-enum-specifier ';'
306
  ```
307
 
308
- The *elaborated-enum-specifier* shall not name a dependent type and the
309
- type shall have a reachable *enum-specifier*.
 
 
 
 
 
 
 
 
310
 
311
- A *using-enum-declaration* introduces the enumerator names of the named
312
- enumeration as if by a *using-declaration* for each enumerator.
313
 
314
  [*Note 1*:
315
 
316
- A *using-enum-declaration* in class scope adds the enumerators of the
317
- named enumeration as members to the scope. This means they are
318
- accessible for member lookup.
319
 
320
  [*Example 1*:
321
 
322
  ``` cpp
323
  enum class fruit { orange, apple };
 
85
 
86
  — *end example*]
87
 
88
  — *end note*]
89
 
90
+ The *identifier* in an *enum-head-name* is not looked up and is
91
+ introduced by the *enum-specifier* or *opaque-enum-declaration*. If the
92
+ *enum-head-name* of an *opaque-enum-declaration* contains a
93
  *nested-name-specifier*, the declaration shall be an explicit
94
  specialization [[temp.expl.spec]].
95
 
96
  The enumeration type declared with an *enum-key* of only `enum` is an
97
  *unscoped enumeration*, and its *enumerator*s are *unscoped
 
102
  declaration of a scoped enumeration. The *type-specifier-seq* of an
103
  *enum-base* shall name an integral type; any cv-qualification is
104
  ignored. An *opaque-enum-declaration* declaring an unscoped enumeration
105
  shall not omit the *enum-base*. The identifiers in an *enumerator-list*
106
  are declared as constants, and can appear wherever constants are
107
+ required. The same identifier shall not appear as the name of multiple
108
+ enumerators in an *enumerator-list*. An *enumerator-definition* with `=`
109
+ gives the associated *enumerator* the value indicated by the
110
+ *constant-expression*. If the first *enumerator* has no *initializer*,
111
+ the value of the corresponding constant is zero. An
112
+ *enumerator-definition* without an *initializer* gives the *enumerator*
113
+ the value obtained by increasing the value of the previous *enumerator*
114
+ by one.
115
 
116
  [*Example 2*:
117
 
118
  ``` cpp
119
  enum { a, b, c=0 };
 
139
  A scoped enumeration shall not be later redeclared as unscoped or with a
140
  different underlying type. An unscoped enumeration shall not be later
141
  redeclared as scoped and each redeclaration shall include an *enum-base*
142
  specifying the same underlying type as in the original declaration.
143
 
144
+ If an *enum-head-name* contains a *nested-name-specifier*, the enclosing
145
+ *enum-specifier* or *opaque-enum-declaration* D shall not inhabit a
146
+ class scope and shall correspond to one or more declarations nominable
147
+ in the class, class template, or namespace to which the
148
+ *nested-name-specifier* refers [[basic.scope.scope]]. All those
149
+ declarations shall have the same target scope; the target scope of D is
150
+ that scope.
 
 
151
 
152
  Each enumeration defines a type that is different from all other types.
153
  Each enumeration also has an *underlying type*. The underlying type can
154
  be explicitly specified using an *enum-base*. For a scoped enumeration
155
  type, the underlying type is `int` if it is not explicitly specified. In
 
173
  preceding enumerator unless the incremented value is not representable
174
  in that type, in which case the type is an unspecified integral type
175
  sufficient to contain the incremented value. If no such type exists,
176
  the program is ill-formed.
177
 
178
+ An enumeration whose underlying type is fixed is an incomplete type
179
+ until immediately after its *enum-base* (if any), at which point it
180
+ becomes a complete type. An enumeration whose underlying type is not
181
+ fixed is an incomplete type until the closing `}` of its
182
+ *enum-specifier*, at which point it becomes a complete type.
 
183
 
184
  For an enumeration whose underlying type is not fixed, the underlying
185
  type is an integral type that can represent all the enumerator values
186
  defined in the enumeration. If no integral type can represent all the
187
  enumerator values, the enumeration is ill-formed. It is
 
199
  all the values of the enumeration type is M. It is possible to define an
200
  enumeration that has values not defined by any of its enumerators. If
201
  the *enumerator-list* is empty, the values of the enumeration are as if
202
  the enumeration had a single enumerator with value 0.[^9]
203
 
204
+ An enumeration has the same size, value representation, and alignment
205
+ requirements [[basic.align]] as its underlying type. Furthermore, each
206
+ value of an enumeration has the same representation as the corresponding
207
+ value of the underlying type.
208
+
209
  Two enumeration types are *layout-compatible enumerations* if they have
210
  the same underlying type.
211
 
212
  The value of an enumerator or an object of an unscoped enumeration type
213
  is converted to an integer by integral promotion [[conv.prom]].
 
228
  values `0`, `1`, `20`, and `21`. Since enumerations are distinct types,
229
  objects of type `color` can be assigned only values of type `color`.
230
 
231
  ``` cpp
232
  color c = 1; // error: type mismatch, no conversion from int to color
233
+ int i = yellow; // OK, yellow converted to integral value 1, integral promotion
234
  ```
235
 
236
  Note that this implicit `enum` to `int` conversion is not provided for a
237
  scoped enumeration:
238
 
 
243
  if (y) { } // error: no Col to bool conversion
244
  ```
245
 
246
  — *end example*]
247
 
248
+ The name of each unscoped enumerator is also bound in the scope that
249
+ immediately contains the *enum-specifier*. An unnamed enumeration that
 
250
  does not have a typedef name for linkage purposes [[dcl.typedef]] and
251
  that has a first enumerator is denoted, for linkage purposes
252
  [[basic.link]], by its underlying type and its first enumerator; such an
253
  enumeration is said to have an enumerator as a name for linkage
254
+ purposes.
 
255
 
256
  [*Note 3*: Each unnamed enumeration with no enumerators is a distinct
257
  type. — *end note*]
258
 
259
  [*Example 4*:
 
276
  }
277
  ```
278
 
279
  — *end example*]
280
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
281
  ### The `using enum` declaration <a id="enum.udecl">[[enum.udecl]]</a>
282
 
283
  ``` bnf
284
  using-enum-declaration:
285
+ using enum using-enum-declarator ';'
286
  ```
287
 
288
+ ``` bnf
289
+ using-enum-declarator:
290
+ nested-name-specifierₒₚₜ identifier
291
+ nested-name-specifierₒₚₜ simple-template-id
292
+ ```
293
+
294
+ A *using-enum-declarator* names the set of declarations found by lookup
295
+ [[basic.lookup.unqual]], [[basic.lookup.qual]] for the
296
+ *using-enum-declarator*. The *using-enum-declarator* shall designate a
297
+ non-dependent type with a reachable *enum-specifier*.
298
 
299
+ A *using-enum-declaration* is equivalent to a *using-declaration* for
300
+ each enumerator.
301
 
302
  [*Note 1*:
303
 
304
+ A *using-enum-declaration* in class scope makes the enumerators of the
305
+ named enumeration available via member lookup.
 
306
 
307
  [*Example 1*:
308
 
309
  ``` cpp
310
  enum class fruit { orange, apple };