Bug 7604 – statically disallow shift amounts provably outside the valid range

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-02-28T04:30:23Z
Last change time
2024-12-13T17:58:44Z
Assigned to
No Owner
Creator
timon.gehr
Moved to GitHub: dmd#18419 →

Comments

Comment #0 by timon.gehr — 2012-02-28T04:30:23Z
This code is rejected: void main(){ int y = 1<<32; } But this goes through: void main(){ int x; int y = 1<<32+(x&1); } Since the semantic analysis step already requires the compiler to be able to compute value ranges, it would make sense to make any shift where the range of the shift amount does not overlap [0..,31] a compile time error.
Comment #1 by r.97all — 2012-09-18T21:24:17Z
In my opinion, if compiler rejects int << 32, ulong >> 64, ..., this also should be a runtime error: // http://dpaste.dzfl.pl/689920e3 void main() { ulong x = ulong.max; foreach (i; 0..64) { (x >> (64 - i)).writeln(); } }
Comment #2 by robert.schadek — 2024-12-13T17:58:44Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18419 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB