D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 16100 - [REG 2.069] Error with -O of struct enumeration value and comma operator
Summary: [REG 2.069] Error with -O of struct enumeration value and comma operator
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 regression
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-05-30 17:03 UTC by Johan Engelen
Modified: 2017-10-08 06:51 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Johan Engelen 2016-05-30 17:03:28 UTC
```
 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 Johan Engelen 2016-05-30 17:05:58 UTC
Also fails with DMD 2.068.2.
(important: "-O" must be used, without "-O" it works)
Comment 2 David Nadlinger 2016-05-31 10:58:26 UTC
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.
Comment 3 Walter Bright 2017-10-08 04:18:26 UTC
I cannot reproduce this problem.