www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22198] New: Compile time bounds checking for static arrays

https://issues.dlang.org/show_bug.cgi?id=22198

          Issue ID: 22198
           Summary: Compile time bounds checking for static arrays
           Product: D
           Version: D2
          Hardware: Other
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: scienticman gmail.com

The following code fails to error out at compile time:

void main(){
    int[10] a;
    auto b = a[0..20];//mistake
}
The error is instead:
core.exception.RangeError onlineapp.d(3): Range violation
----------------
??:? _d_arrayboundsp [0x555bdc2b6c29]
./onlineapp.d:3 _Dmain [0x555bdc2b6b86]

This can easily be caught at compile time, please do so.

Thank you for your time!

--
Aug 11 2021