| 1 |
// REQUIRED_ARGS: -boundscheck=off |
| 2 |
// PERMUTE_ARGS: -inline -g -O |
| 3 |
|
| 4 |
import core.exception : RangeError; |
| 5 |
|
| 6 |
// Check for RangeError is thrown |
| 7 |
bool thrown(T)(lazy T cond) |
| 8 |
{ |
| 9 |
import core.exception; |
| 10 |
bool f = false; |
| 11 |
try { cond(); } catch (RangeError e) { f = true; } |
| 12 |
return f; |
| 13 |
} |
| 14 |
|
| 15 |
@safe int safeIndex (int[] arr) { return arr[2]; } |
| 16 |
@trusted int trustedIndex(int[] arr) { return arr[2]; } |
| 17 |
@system int systemIndex (int[] arr) { return arr[2]; } |
| 18 |
|
| 19 |
void main() |
| 20 |
{ |
| 21 |
int[3] data = [1,2,3]; |
| 22 |
int[] arr = data[0..2]; |
| 23 |
|
| 24 |
assert(arr. safeIndex() == 3); |
| 25 |
assert(arr.trustedIndex() == 3); |
| 26 |
assert(arr. systemIndex() == 3); |
| 27 |
} |