[Issue 22937] New: identity comparison of strings / struct literals not constant folded
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Mar 25 21:44:59 UTC 2022
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 at puremagic.com
Reporter: dkorpel at 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.
--
More information about the Digitalmars-d-bugs
mailing list