Skip to content

Commit 64043b7

Browse files
ntreldlang-bot
authored andcommitted
Fix Issue 23511 - Incrementing a not supported type in enum
Also remove noisy unnecessary AssignExpression links.
1 parent d0615a1 commit 64043b7

File tree

1 file changed

+35
-33
lines changed

1 file changed

+35
-33
lines changed

spec/enum.dd

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -71,36 +71,37 @@ $(H2 $(LNAME2 named_enums, Named Enums))
7171

7272

7373
$(P If the $(I EnumBaseType) is not explicitly set, and the first
74-
$(I EnumMember) has an $(ASSIGNEXPRESSION), it is set to the type of that
75-
$(ASSIGNEXPRESSION). Otherwise, it defaults to
74+
$(I EnumMember) has an *AssignExpression*, it is set to the type of that
75+
*AssignExpression*. Otherwise, it defaults to
7676
type $(CODE int).)
7777

7878
$(P Named enum members may not have individual $(I Type)s.
7979
)
8080

81-
8281
$(P A named enum member can be implicitly cast to its $(GLINK EnumBaseType),
8382
but $(I EnumBaseType) types
8483
cannot be implicitly cast to an enum type.
8584
)
8685

87-
$(P The value of an $(GLINK EnumMember) is given by its $(ASSIGNEXPRESSION).
88-
If there is no $(ASSIGNEXPRESSION) and it is the first $(I EnumMember),
86+
$(P The value of an $(GLINK EnumMember) is given by its *AssignExpression* if present.
87+
If there is no *AssignExpression* and it is the first $(I EnumMember),
8988
its value is $(GLINK EnumBaseType)`.init`.
89+
If there is no *AssignExpression* and it is not the first $(I EnumMember),
90+
it is given the value of the previous $(I EnumMember)`+1`:)
91+
92+
* If the value of the previous $(I EnumMember) is $(GLINK EnumBaseType)`.max`,
93+
it is an error. This prevents value overflow. It is an error if the previous
94+
member cannot be compared with *EnumBaseType*`.max` at compile-time.
95+
* It is an error if the base type does not define a compile-time
96+
evaluable `+1` operation.
97+
* If the value of the previous $(I EnumMember)`+1` is the same as the
98+
value of the previous $(I EnumMember), it is an error. (This can happen
99+
with floating point types).
100+
101+
$(P All $(I EnumMember)s are in scope for the *AssignExpression*s.
90102
)
91103

92-
$(P If there is no $(ASSIGNEXPRESSION) and it is not the first $(I EnumMember),
93-
it is given the value of the previous $(I EnumMember)`+1`.
94-
If the value of the previous $(I EnumMember) is $(GLINK EnumBaseType)`.max`,
95-
it is an error.
96-
If the value of the previous $(I EnumMember)`+1` is the same as the
97-
value of the previous $(I EnumMember), it is an error. (This can happen
98-
with floating point types.)
99-
)
100-
101-
$(P All $(I EnumMember)s are in scope for the $(ASSIGNEXPRESSION)s.
102-
)
103-
104+
$(SPEC_RUNNABLE_EXAMPLE_FAIL
104105
---
105106
enum A = 3;
106107
enum B
@@ -120,7 +121,7 @@ enum E : C
120121
E2 // error, C.D is C.max
121122
}
122123
---
123-
124+
)
124125

125126
$(P An empty enum body (For example $(CODE enum E;)) signifies an opaque
126127
enum - the enum members are unknown.)
@@ -196,22 +197,23 @@ enum { A, B, C } // anonymous enum
196197
$(P Enums must have at least one member.
197198
)
198199

199-
$(P The value of an $(I EnumMember) is given by its $(ASSIGNEXPRESSION).
200-
If there is no $(ASSIGNEXPRESSION) and it is the first $(I EnumMember),
200+
$(P The value of an $(I EnumMember) is given by its *AssignExpression* if present.
201+
If there is no *AssignExpression* and it is the first $(I EnumMember),
201202
its value is the $(CODE .init) property of the $(I EnumMember)'s type.
202-
)
203-
204-
$(P If there is no $(ASSIGNEXPRESSION) and it is not the first $(I EnumMember),
205-
it is given the value of the previous $(I EnumMember)`+1`.
206-
If the value of the previous $(I EnumMember) is the `.max` property
207-
if the previous $(I EnumMember)'s type,
208-
it is an error.
209-
If the value of the previous $(I EnumMember)`+1` is the same as the
210-
value of the previous $(I EnumMember), it is an error. (This can happen
211-
with floating point types.)
212-
)
213-
214-
$(P All $(I EnumMember)s are in scope for the $(ASSIGNEXPRESSION)s.
203+
If there is no *AssignExpression* and it is not the first $(I EnumMember),
204+
it is given the value of the previous $(I EnumMember)`+1`:)
205+
206+
* If the value of the previous $(I EnumMember) is the `.max` property
207+
of the previous $(I EnumMember)'s type, it is an error.
208+
This prevents value overflow. It is an error if the previous
209+
member cannot be compared with its `.max` property at compile-time.
210+
* It is an error if the type of the previous member does not define a compile-time
211+
evaluable `+1` operation.
212+
* If the value of the previous $(I EnumMember)`+1` is the same as the
213+
value of the previous $(I EnumMember), it is an error. (This can happen
214+
with floating point types).
215+
216+
$(P All $(I EnumMember)s are in scope for the *AssignExpression*s.
215217
)
216218

217219
------

0 commit comments

Comments
 (0)