Skip to content

Commit b076d13

Browse files
authored
First enum member is converted from 0 to base type (#3694)
Fix Issue 18578 - First enum value assigned 0 instead of EnumBaseType.init.
1 parent 139643f commit b076d13

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

spec/enum.dd

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ f = Foo.E; // OK
9696

9797
$(P The value of an $(GLINK EnumMember) is given by its *AssignExpression* if present.
9898
If there is no *AssignExpression* and it is the first $(I EnumMember),
99-
its value is $(GLINK EnumBaseType)`.init`.
99+
its value is converted to $(GLINK EnumBaseType) from `0`.
100100
If there is no *AssignExpression* and it is not the first $(I EnumMember),
101101
it is given the value of the previous $(I EnumMember)`+1`:)
102102

@@ -109,6 +109,19 @@ f = Foo.E; // OK
109109
value of the previous $(I EnumMember), it is an error. (This can happen
110110
with floating point types).
111111

112+
$(SPEC_RUNNABLE_EXAMPLE_FAIL
113+
---
114+
enum E : char
115+
{
116+
a,
117+
b = char.max,
118+
c // overflow
119+
}
120+
121+
static assert(E.a == 0);
122+
---
123+
)
124+
112125
$(P All $(I EnumMember)s are in scope for the *AssignExpression*s.
113126
)
114127

0 commit comments

Comments
 (0)