digitalmars.D.bugs - [Issue 22937] New: identity comparison of strings / struct literals
- d-bugmail puremagic.com (32/32) Mar 25 2022 https://issues.dlang.org/show_bug.cgi?id=22937
https://issues.dlang.org/show_bug.cgi?id=22937 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: https://github.com/dlang/dmd/pull/13780 ``` 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 == EXP.null_)) ``` isConst checks for number literals, but not strings or struct literals. --
Mar 25 2022