From Jason Turner

[dcl.enum]

Diff to HTML by rtfpessoa

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