Any reason why ++1 is not folded to a new constant?

Basile B. b2.temp at gmx.com
Tue Oct 20 12:41:48 UTC 2020


I've reached a similar problem in another language and I wanted 
to see what is the D policy. I've been surprised by the result. 
It seems that there's no special case for compile-time-only 
values, eg this case of RValue:
---
void main()
{
     writeln(++1); // NG: cannot modify constant `1`
}
---

is there any reasons why ++1 is not optimized to 2 ?

Thanks for the enlightment.


More information about the Digitalmars-d mailing list