Bug 6884 – Some static bounds tests on dynamic arrays too

Status
RESOLVED
Resolution
LATER
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-11-02T17:16:28Z
Last change time
2021-01-24T06:23:30Z
Keywords
diagnostic
Assigned to
No Owner
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2011-11-02T17:16:28Z
I'd like DMD to catch at compile-time some of the following bugs (with DMD 2.056 this gives no compile-time errors): void main() { int[] x = new int[5]; x[$] = 1; // easy x[x.length] = 1; // idem enum size_t n = 2; x[$ + n] = 2; // not too much hard if n is unsigned x[x.length + n] = 2; // idem } See also bug 6883
Comment #1 by maxhaton — 2021-01-24T06:23:30Z
Halting problem aside, this would require a lot of speculative work in the compiler (Being slow after finding ill-formed code is fine, being slow *to* find ill-formed code is more of a problem)