www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 16100] New: Error with -O of struct enumeration value and


          Issue ID: 16100
           Summary: Error with -O of struct enumeration value and comma
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: jbc.engelen gmail.com

 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:

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).

May 30 2016