www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22937] New: identity comparison of strings / struct literals


          Issue ID: 22937
           Summary: identity comparison of strings / struct literals not
                    constant folded
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: dkorpel live.nl

I encountered this while fixing issue 3632:

struct S { int f; }
void main()
    assert(S(0) is S(0));
    assert("a" is "a");

They are not constant folded to `true`, as evidenced by inspecting with
-vcg-ast or -vasm. `visitIdentity` in `optimize.d` has this condition:

if ((e.e1.isConst() && e.e2.isConst()) || (e.e1.op == EXP.null_ && e.e2.op ==

isConst checks for number literals, but not strings or struct literals.

Mar 25 2022