From Jason Turner

[dcl.enum]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp2v99nvf3/{from.md → to.md} +42 -24
tmp/tmp2v99nvf3/{from.md → to.md} RENAMED
@@ -56,11 +56,22 @@ enumerator:
56
  ```
57
 
58
  The optional *attribute-specifier-seq* in the *enum-head* and the
59
  *opaque-enum-declaration* appertains to the enumeration; the attributes
60
  in that *attribute-specifier-seq* are thereafter considered attributes
61
- of the enumeration whenever it is named.
 
 
 
 
 
 
 
 
 
 
 
62
 
63
  The enumeration type declared with an *enum-key* of only `enum` is an
64
  unscoped enumeration, and its *enumerator*s are *unscoped enumerators*.
65
  The *enum-key*s `enum class` and `enum struct` are semantically
66
  equivalent; an enumeration type declared with one of these is a *scoped
@@ -103,33 +114,40 @@ declared directly in the class or namespace to which the
103
  by a *using-declaration*), and the *enum-specifier* shall appear in a
104
  namespace enclosing the previous declaration.
105
 
106
  Each enumeration defines a type that is different from all other types.
107
  Each enumeration also has an underlying type. The underlying type can be
108
- explicitly specified using *enum-base*; if not explicitly specified, the
109
- underlying type of a scoped enumeration type is `int`. In these cases,
110
- the underlying type is said to be *fixed*. Following the closing brace
111
- of an *enum-specifier*, each enumerator has the type of its enumeration.
112
- If the underlying type is fixed, the type of each *enumerator* prior to
113
- the closing brace is the underlying type and the *constant-expression*
114
- in the *enumerator-definition* shall be a converted constant expression
115
- of the underlying type ([[expr.const]]); if the initializing value of
116
- an *enumerator* cannot be represented by the underlying type, the
117
- program is ill-formed. If the underlying type is not fixed, the type of
118
- each enumerator is the type of its initializing value:
119
 
120
- - If an initializer is specified for an enumerator, the initializing
121
- value has the same type as the expression and the
122
  *constant-expression* shall be an integral constant expression (
123
- [[expr.const]]).
124
- - If no initializer is specified for the first enumerator, the
125
- initializing value has an unspecified integral type.
126
- - Otherwise the type of the initializing value is the same as the type
127
- of the initializing value of the preceding enumerator unless the
128
- incremented value is not representable in that type, in which case the
129
- type is an unspecified integral type sufficient to contain the
130
- incremented value. If no such type exists, the program is ill-formed.
 
 
 
 
 
 
 
 
 
131
 
132
  For an enumeration whose underlying type is not fixed, the underlying
133
  type is an integral type that can represent all the enumerator values
134
  defined in the enumeration. If no integral type can represent all the
135
  enumerator values, the enumeration is ill-formed. It is
@@ -151,13 +169,13 @@ integer. bₘᵢₙ is zero if eₘᵢₙ is non-negative and -(bₘₐₓ+K) ot
151
  The size of the smallest bit-field large enough to hold all the values
152
  of the enumeration type is max(M,1) if bₘᵢₙ is zero and M+1 otherwise.
153
  It is possible to define an enumeration that has values not defined by
154
  any of its enumerators. If the *enumerator-list* is empty, the values of
155
  the enumeration are as if the enumeration had a single enumerator with
156
- value 0.[^5]
157
 
158
- Two enumeration types are layout-compatible if they have the same
159
  *underlying type*.
160
 
161
  The value of an enumerator or an object of an unscoped enumeration type
162
  is converted to an integer by integral promotion ([[conv.prom]]).
163
 
 
56
  ```
57
 
58
  The optional *attribute-specifier-seq* in the *enum-head* and the
59
  *opaque-enum-declaration* appertains to the enumeration; the attributes
60
  in that *attribute-specifier-seq* are thereafter considered attributes
61
+ of the enumeration whenever it is named. A `:` following “`enum`
62
+ *identifier*” is parsed as part of an *enum-base*. This resolves a
63
+ potential ambiguity between the declaration of an enumeration with an
64
+ *enum-base* and the declaration of an unnamed bit-field of enumeration
65
+ type.
66
+
67
+ ``` cpp
68
+ struct S {
69
+ enum E : int {};
70
+ enum E : int {}; // error: redeclaration of enumeration
71
+ };
72
+ ```
73
 
74
  The enumeration type declared with an *enum-key* of only `enum` is an
75
  unscoped enumeration, and its *enumerator*s are *unscoped enumerators*.
76
  The *enum-key*s `enum class` and `enum struct` are semantically
77
  equivalent; an enumeration type declared with one of these is a *scoped
 
114
  by a *using-declaration*), and the *enum-specifier* shall appear in a
115
  namespace enclosing the previous declaration.
116
 
117
  Each enumeration defines a type that is different from all other types.
118
  Each enumeration also has an underlying type. The underlying type can be
119
+ explicitly specified using an *enum-base*. For a scoped enumeration
120
+ type, the underlying type is `int` if it is not explicitly specified. In
121
+ both of these cases, the underlying type is said to be *fixed*.
122
+ Following the closing brace of an *enum-specifier*, each enumerator has
123
+ the type of its enumeration. If the underlying type is fixed, the type
124
+ of each enumerator prior to the closing brace is the underlying type and
125
+ the *constant-expression* in the *enumerator-definition* shall be a
126
+ converted constant expression of the underlying type ([[expr.const]]).
127
+ If the underlying type is not fixed, the type of each enumerator prior
128
+ to the closing brace is determined as follows:
 
129
 
130
+ - If an initializer is specified for an enumerator, the
 
131
  *constant-expression* shall be an integral constant expression (
132
+ [[expr.const]]). If the expression has unscoped enumeration type, the
133
+ enumerator has the underlying type of that enumeration type, otherwise
134
+ it has the same type as the expression.
135
+ - If no initializer is specified for the first enumerator, its type is
136
+ an unspecified signed integral type.
137
+ - Otherwise the type of the enumerator is the same as that of the
138
+ preceding enumerator unless the incremented value is not representable
139
+ in that type, in which case the type is an unspecified integral type
140
+ sufficient to contain the incremented value. If no such type exists,
141
+ the program is ill-formed.
142
+
143
+ An enumeration whose underlying type is fixed is an incomplete type from
144
+ its point of declaration ([[basic.scope.pdecl]]) to immediately after
145
+ its *enum-base* (if any), at which point it becomes a complete type. An
146
+ enumeration whose underlying type is not fixed is an incomplete type
147
+ from its point of declaration to immediately after the closing `}` of
148
+ its *enum-specifier*, at which point it becomes a complete type.
149
 
150
  For an enumeration whose underlying type is not fixed, the underlying
151
  type is an integral type that can represent all the enumerator values
152
  defined in the enumeration. If no integral type can represent all the
153
  enumerator values, the enumeration is ill-formed. It is
 
169
  The size of the smallest bit-field large enough to hold all the values
170
  of the enumeration type is max(M,1) if bₘᵢₙ is zero and M+1 otherwise.
171
  It is possible to define an enumeration that has values not defined by
172
  any of its enumerators. If the *enumerator-list* is empty, the values of
173
  the enumeration are as if the enumeration had a single enumerator with
174
+ value 0.[^4]
175
 
176
+ Two enumeration types are *layout-compatible* if they have the same
177
  *underlying type*.
178
 
179
  The value of an enumerator or an object of an unscoped enumeration type
180
  is converted to an integer by integral promotion ([[conv.prom]]).
181