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.
Comment #1 by maxhaton — 2022-05-21T01:08:57Z
Is it a bug though?
The frontend should be doing less constant folding not more.
Comment #2 by dkorpel — 2022-05-21T09:22:57Z
(In reply to mhh from comment #1)
> The frontend should be doing less constant folding not more.
Which operator/type combinations should be constant folded, and why? To me, it would make sense to constant fold all built in operators on literal values. I don't expect the compiler to ever generate a runtime addition for '3 + 4', even in debug builds.
Comment #3 by robert.schadek — 2024-12-13T19:21:44Z