Bug 23511 – Incrementing a not supported type in enum
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
dlang.org
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-11-26T11:19:24Z
Last change time
2022-12-10T18:17:53Z
Keywords
pull
Assigned to
No Owner
Creator
Victor Porton
Comments
Comment #0 by porton — 2022-11-26T11:19:24Z
As expected, DMD does not compile this:
enum {
string A = "12",
B,
}
But AFAIK nothing in the specification implies that this is not compilable. I can devise other possible interpretations of the specification than being not compilable, for example, undefined behavior.
Need to say in the specification that stuff like this does not compile.
Comment #1 by nick — 2022-11-27T18:40:56Z
> As expected, DMD does not compile this
Yes, though I've tweaked the error message in my local copy as it should be clearer. (I'll submit it soon).
> nothing in the specification implies that this is not compilable
"If there is no AssignExpression and it is not the first EnumMember, it is given the value of the previous EnumMember+1. If the value of the previous EnumMember is EnumBaseType.max, it is an error."
https://dlang.org/spec/enum.html#named_enums
'the value of the previous EnumMember+1' implies that expression must compile.
Comment #2 by nick — 2022-12-10T13:51:42Z
> 'the value of the previous EnumMember+1' implies that expression must compile.
Actually I have made a pull to clarify the spec which adds some more details.
Comment #3 by dlang-bot — 2022-12-10T18:17:53Z
dlang/dlang.org pull request #3462 "Fix Issue 23511 - Incrementing a not supported type in enum" was merged into master:
- 8dd0fb161917abf92b163afdff3e2c319ff181dc by Nick Treleaven:
Fix Issue 23511 - Incrementing a not supported type in enum
Also remove noisy unnecessary AssignExpression links.
https://github.com/dlang/dlang.org/pull/3462