Bug 16100 – [REG 2.069] Error with -O of struct enumeration value and comma operator
Status
RESOLVED
Resolution
WORKSFORME
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-05-30T17:03:28Z
Last change time
2017-10-08T06:51:26Z
Assigned to
No Owner
Creator
Johan Engelen
Comments
Comment #0 by jbc.engelen — 2016-05-30T17:03:28Z
```
bool test16022_structs()
{
struct A
{
int i;
string s;
}
enum Type { Colon = A(0, "zero"), Comma = A(1, "one") }
Type type;
return type == Type.Colon, type == Type.Comma;
}
```
Fails with -O , see https://github.com/dlang/dmd/pull/5825
Related bug report:
https://issues.dlang.org/show_bug.cgi?id=16022
The underlying reason for problems with this comma operator and enums in LDC is the following (and I suspect the same is the case in DMD): it is the only time (in the dmd-testsuite) that in the AST a DotVarExp -> VarExp is used for each field of the struct enum value ("Type.Colon" in this case), whereas in other cases the DotVarExp is constant folded to the elements of the struct (e.g. IntegerExp). So the backend has to properly handle VarExp's pointing to enum values (the VarDeclaration of the VarExp is an EnumMember); enum members are not emitted as variables and thus it is a quirky case for the VarExp.
Nowhere else is this tested, and so there are troubles with that.
The related bug report and the fix for it fixed one case where the enum member is an integer; in the testcase above the case is tested where the enum member is a struct.
Constant folding for the LHS of the comma operator would also fix this issue (but with a remaining latent bug, unless VarExp of EnumMember is disallowed in the AST that is passed to the backend).
Comment #1 by jbc.engelen — 2016-05-30T17:05:58Z
Also fails with DMD 2.068.2.
(important: "-O" must be used, without "-O" it works)
Comment #2 by code — 2016-05-31T10:58:26Z
It seems that versions prior to 2.069 at least statically rejected the code. Even though this was probably in error, it's still better than an ICE, so marking as regression.