[Issue 13228] Value range analysis for the length of slices
    via Digitalmars-d-bugs 
    digitalmars-d-bugs at puremagic.com
       
    Tue Nov 11 12:43:30 PST 2014
    
    
  
https://issues.dlang.org/show_bug.cgi?id=13228
--- Comment #2 from bearophile_hugs at eml.cc ---
I think simple cases like this could be supported by the same length range
analysis:
void foo(int[7]) {}
void main() {
    int[3] a;
    int[2] b, c;
    foo(a ~ b ~ c); // No run-time length test here.
}
void foo(int[2]) {}
void main() {
    int[5] a;
    const int len = 2;
    foo(a[0 .. len]); // OK
    const int[] b = new int[2];
    foo(a[0 .. b.length]); // Currently an error
}
Here the run-time test of the length of 'a' can be omitted, because it can't be
longer than 'b':
int n = 8;
void main() {
    const a = new int[n % 5];
    int[10] b;
    b[0 .. a.length] = 0;
}
--
    
    
More information about the Digitalmars-d-bugs
mailing list