built-in int[] opSliceOpAssign throws?

monarch_dodra monarchdodra at gmail.com
Wed Sep 12 02:20:54 PDT 2012


--------
nothrow void foo1(int[] a)
{
     foreach(i; 0..10)
     {
         a[i]  = 5;
         a[i] += 5;
     }
}

nothrow void foo2(int[] a) //10
{
     a[0..10]  = 5;  //12
     a[0..10] += 5;  //13
}
--------
main.d(13): Error: _arrayExpSliceAddass_i is not nothrow
main.d(10): Error: function main.foo2 'foo2' is nothrow yet may 
throw
--------

Making an out of range call in foo2 (after removing nothrow) 
throws an _ERROR_ in both line 12 and 13 (if commenting 12):
core.exception.RangeError at main(12): Range violation
core.exception.RangeError at main(13): Range violation
Is there any situation where it actually *could* throw an 
exception?

This is a bug? I did not find any entries in Bug report. Should I 
report this?

I need to make the above call in a nothrow function. Is there any 
way to make it work, without any run-time cost?


More information about the Digitalmars-d-learn mailing list