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: nob...@puremagic.com Reporter: dkor...@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. --