From Jason Turner

[dcl.enum]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpmrmnr423/{from.md → to.md} +47 -51
tmp/tmpmrmnr423/{from.md → to.md} RENAMED
@@ -1,19 +1,19 @@
1
- ## Enumeration declarations <a id="dcl.enum">[[dcl.enum]]</a>
2
 
3
- An enumeration is a distinct type ([[basic.compound]]) with named
4
  constants. Its name becomes an *enum-name* within its scope.
5
 
6
  ``` bnf
7
  enum-name:
8
  identifier
9
  ```
10
 
11
  ``` bnf
12
  enum-specifier:
13
  enum-head '{' enumerator-listₒₚₜ '}'
14
- enum-head '{' enumerator-list ', }'
15
  ```
16
 
17
  ``` bnf
18
  enum-head:
19
  enum-key attribute-specifier-seqₒₚₜ enum-head-nameₒₚₜ enum-baseₒₚₜ
@@ -24,18 +24,18 @@ enum-head-name:
24
  nested-name-specifierₒₚₜ identifier
25
  ```
26
 
27
  ``` bnf
28
  opaque-enum-declaration:
29
- enum-key attribute-specifier-seqₒₚₜ nested-name-specifierₒₚₜ identifier enum-baseₒₚₜ ';'
30
  ```
31
 
32
  ``` bnf
33
  enum-key:
34
- 'enum'
35
- 'enum class'
36
- 'enum struct'
37
  ```
38
 
39
  ``` bnf
40
  enum-base:
41
  ':' type-specifier-seq
@@ -83,19 +83,20 @@ bit-field of enumeration type.
83
 
84
  — *end example*]
85
 
86
  — *end note*]
87
 
88
- If an *opaque-enum-declaration* contains a *nested-name-specifier*, the
89
- declaration shall be an explicit specialization ([[temp.expl.spec]]).
 
90
 
91
  The enumeration type declared with an *enum-key* of only `enum` is an
92
  *unscoped enumeration*, and its *enumerator*s are *unscoped
93
  enumerators*. The *enum-key*s `enum class` and `enum struct` are
94
  semantically equivalent; an enumeration type declared with one of these
95
  is a *scoped enumeration*, and its *enumerator*s are *scoped
96
- enumerators*. The optional *identifier* shall not be omitted in the
97
  declaration of a scoped enumeration. The *type-specifier-seq* of an
98
  *enum-base* shall name an integral type; any cv-qualification is
99
  ignored. An *opaque-enum-declaration* declaring an unscoped enumeration
100
  shall not omit the *enum-base*. The identifiers in an *enumerator-list*
101
  are declared as constants, and can appear wherever constants are
@@ -123,42 +124,45 @@ that enumerator.
123
 
124
  An *opaque-enum-declaration* is either a redeclaration of an enumeration
125
  in the current scope or a declaration of a new enumeration.
126
 
127
  [*Note 2*: An enumeration declared by an *opaque-enum-declaration* has
128
- fixed underlying type and is a complete type. The list of enumerators
129
  can be provided in a later redeclaration with an
130
  *enum-specifier*. — *end note*]
131
 
132
  A scoped enumeration shall not be later redeclared as unscoped or with a
133
  different underlying type. An unscoped enumeration shall not be later
134
  redeclared as scoped and each redeclaration shall include an *enum-base*
135
  specifying the same underlying type as in the original declaration.
136
 
137
- If the *enum-key* is followed by a *nested-name-specifier*, the
138
- *enum-specifier* shall refer to an enumeration that was previously
139
- declared directly in the class or namespace to which the
140
- *nested-name-specifier* refers (i.e., neither inherited nor introduced
141
- by a *using-declaration*), and the *enum-specifier* shall appear in a
142
- namespace enclosing the previous declaration.
 
 
 
143
 
144
  Each enumeration defines a type that is different from all other types.
145
  Each enumeration also has an *underlying type*. The underlying type can
146
  be explicitly specified using an *enum-base*. For a scoped enumeration
147
  type, the underlying type is `int` if it is not explicitly specified. In
148
  both of these cases, the underlying type is said to be *fixed*.
149
  Following the closing brace of an *enum-specifier*, each enumerator has
150
  the type of its enumeration. If the underlying type is fixed, the type
151
  of each enumerator prior to the closing brace is the underlying type and
152
  the *constant-expression* in the *enumerator-definition* shall be a
153
- converted constant expression of the underlying type ([[expr.const]]).
154
- If the underlying type is not fixed, the type of each enumerator prior
155
- to the closing brace is determined as follows:
156
 
157
  - If an initializer is specified for an enumerator, the
158
- *constant-expression* shall be an integral constant expression (
159
- [[expr.const]]). If the expression has unscoped enumeration type, the
160
  enumerator has the underlying type of that enumeration type, otherwise
161
  it has the same type as the expression.
162
  - If no initializer is specified for the first enumerator, its type is
163
  an unspecified signed integral type.
164
  - Otherwise the type of the enumerator is the same as that of the
@@ -166,12 +170,12 @@ to the closing brace is determined as follows:
166
  in that type, in which case the type is an unspecified integral type
167
  sufficient to contain the incremented value. If no such type exists,
168
  the program is ill-formed.
169
 
170
  An enumeration whose underlying type is fixed is an incomplete type from
171
- its point of declaration ([[basic.scope.pdecl]]) to immediately after
172
- its *enum-base* (if any), at which point it becomes a complete type. An
173
  enumeration whose underlying type is not fixed is an incomplete type
174
  from its point of declaration to immediately after the closing `}` of
175
  its *enum-specifier*, at which point it becomes a complete type.
176
 
177
  For an enumeration whose underlying type is not fixed, the underlying
@@ -183,30 +187,24 @@ type except that the underlying type shall not be larger than `int`
183
  unless the value of an enumerator cannot fit in an `int` or
184
  `unsigned int`. If the *enumerator-list* is empty, the underlying type
185
  is as if the enumeration had a single enumerator with value 0.
186
 
187
  For an enumeration whose underlying type is fixed, the values of the
188
- enumeration are the values of the underlying type. Otherwise, for an
189
- enumeration where eₘin is the smallest enumerator and eₘax is the
190
- largest, the values of the enumeration are the values in the range bₘin
191
- to bₘax, defined as follows: Let K be 1 for a two’s complement
192
- representation and 0 for a ones’ complement or sign-magnitude
193
- representation. bₘax is the smallest value greater than or equal to
194
- max(|eₘin| - K, |eₘax|) and equal to $2^M-1$, where M is a non-negative
195
- integer. bₘin is zero if eₘin is non-negative and -(bₘax+K) otherwise.
196
- The size of the smallest bit-field large enough to hold all the values
197
- of the enumeration type is max(M,1) if bₘin is zero and M+1 otherwise.
198
- It is possible to define an enumeration that has values not defined by
199
- any of its enumerators. If the *enumerator-list* is empty, the values of
200
- the enumeration are as if the enumeration had a single enumerator with
201
- value 0.[^4]
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]]).
208
 
209
  [*Example 3*:
210
 
211
  ``` cpp
212
  enum color { red, yellow, green=20, blue };
@@ -239,12 +237,20 @@ if (y) { } // error: no Col to bool conversion
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. These names obey the scope
245
- rules defined for all names in  [[basic.scope]] and  [[basic.lookup]].
 
 
 
 
 
 
 
 
246
 
247
  [*Example 4*:
248
 
249
  ``` cpp
250
  enum direction { left='l', right='r' };
@@ -288,15 +294,5 @@ void g(X* p) {
288
  }
289
  ```
290
 
291
  — *end example*]
292
 
293
- If an *enum-head* contains a *nested-name-specifier*, the
294
- *enum-specifier* shall refer to an enumeration that was previously
295
- declared directly in the class or namespace to which the
296
- *nested-name-specifier* refers, or in an element of the inline namespace
297
- set ([[namespace.def]]) of that namespace (i.e., not merely inherited
298
- or introduced by a *using-declaration*), and the *enum-specifier* shall
299
- appear in a namespace enclosing the previous declaration. In such cases,
300
- the *nested-name-specifier* of the *enum-head* of the definition shall
301
- not begin with a *decltype-specifier*.
302
-
 
1
+ ### Enumeration declarations <a id="dcl.enum">[[dcl.enum]]</a>
2
 
3
+ An enumeration is a distinct type [[basic.compound]] with named
4
  constants. Its name becomes an *enum-name* within its scope.
5
 
6
  ``` bnf
7
  enum-name:
8
  identifier
9
  ```
10
 
11
  ``` bnf
12
  enum-specifier:
13
  enum-head '{' enumerator-listₒₚₜ '}'
14
+ enum-head '{' enumerator-list ',' '}'
15
  ```
16
 
17
  ``` bnf
18
  enum-head:
19
  enum-key attribute-specifier-seqₒₚₜ enum-head-nameₒₚₜ enum-baseₒₚₜ
 
24
  nested-name-specifierₒₚₜ identifier
25
  ```
26
 
27
  ``` bnf
28
  opaque-enum-declaration:
29
+ enum-key attribute-specifier-seqₒₚₜ enum-head-name enum-baseₒₚₜ ';'
30
  ```
31
 
32
  ``` bnf
33
  enum-key:
34
+ enum
35
+ enum class
36
+ enum struct
37
  ```
38
 
39
  ``` bnf
40
  enum-base:
41
  ':' type-specifier-seq
 
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
94
  enumerators*. The *enum-key*s `enum class` and `enum struct` are
95
  semantically equivalent; an enumeration type declared with one of these
96
  is a *scoped enumeration*, and its *enumerator*s are *scoped
97
+ 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
 
124
 
125
  An *opaque-enum-declaration* is either a redeclaration of an enumeration
126
  in the current scope or a declaration of a new enumeration.
127
 
128
  [*Note 2*: An enumeration declared by an *opaque-enum-declaration* has
129
+ a fixed underlying type and is a complete type. The list of enumerators
130
  can be provided in a later redeclaration with an
131
  *enum-specifier*. — *end note*]
132
 
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
152
  both of these cases, the underlying type is said to be *fixed*.
153
  Following the closing brace of an *enum-specifier*, each enumerator has
154
  the type of its enumeration. If the underlying type is fixed, the type
155
  of each enumerator prior to the closing brace is the underlying type and
156
  the *constant-expression* in the *enumerator-definition* shall be a
157
+ converted constant expression of the underlying type [[expr.const]]. If
158
+ the underlying type is not fixed, the type of each enumerator prior to
159
+ the closing brace is determined as follows:
160
 
161
  - If an initializer is specified for an enumerator, the
162
+ *constant-expression* shall be an integral constant expression
163
+ [[expr.const]]. If the expression has unscoped enumeration type, the
164
  enumerator has the underlying type of that enumeration type, otherwise
165
  it has the same type as the expression.
166
  - If no initializer is specified for the first enumerator, its type is
167
  an unspecified signed integral type.
168
  - Otherwise the type of the enumerator is the same as that of the
 
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
 
187
  unless the value of an enumerator cannot fit in an `int` or
188
  `unsigned int`. If the *enumerator-list* is empty, the underlying type
189
  is as if the enumeration had a single enumerator with value 0.
190
 
191
  For an enumeration whose underlying type is fixed, the values of the
192
+ enumeration are the values of the underlying type. Otherwise, the values
193
+ of the enumeration are the values representable by a hypothetical
194
+ integer type with minimal width M such that all enumerators can be
195
+ 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]].
206
 
207
  [*Example 3*:
208
 
209
  ``` cpp
210
  enum color { red, yellow, green=20, blue };
 
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*:
254
 
255
  ``` cpp
256
  enum direction { left='l', right='r' };
 
294
  }
295
  ```
296
 
297
  — *end example*]
298