Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add -boundscheck=[on|safeonly|off] option
Replaces -noboundscheck (which becomes deprecated) Fixes issue #12550
- Loading branch information
1 parent
212814e
commit 23748b9
Showing
4 changed files
with
119 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// REQUIRED_ARGS: -boundscheck=off | ||
// PERMUTE_ARGS: -inline -g -O | ||
|
||
import core.exception : RangeError; | ||
|
||
// Check for RangeError is thrown | ||
bool thrown(T)(lazy T cond) | ||
{ | ||
import core.exception; | ||
bool f = false; | ||
try { cond(); } catch (RangeError e) { f = true; } | ||
return f; | ||
} | ||
|
||
@safe int safeIndex (int[] arr) { return arr[2]; } | ||
@trusted int trustedIndex(int[] arr) { return arr[2]; } | ||
@system int systemIndex (int[] arr) { return arr[2]; } | ||
|
||
void main() | ||
{ | ||
int[3] data = [1,2,3]; | ||
int[] arr = data[0..2]; | ||
|
||
assert(arr. safeIndex() == 3); | ||
assert(arr.trustedIndex() == 3); | ||
assert(arr. systemIndex() == 3); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// REQUIRED_ARGS: -boundscheck=on | ||
// PERMUTE_ARGS: -inline -g -O | ||
|
||
import core.exception : RangeError; | ||
|
||
// Check for RangeError is thrown | ||
bool thrown(T)(lazy T cond) | ||
{ | ||
import core.exception; | ||
bool f = false; | ||
try { cond(); } catch (RangeError e) { f = true; } | ||
return f; | ||
} | ||
|
||
@safe int safeIndex (int[] arr) { return arr[2]; } | ||
@trusted int trustedIndex(int[] arr) { return arr[2]; } | ||
@system int systemIndex (int[] arr) { return arr[2]; } | ||
|
||
void main() | ||
{ | ||
int[3] data = [1,2,3]; | ||
int[] arr = data[0..2]; | ||
|
||
assert(arr. safeIndex().thrown); | ||
assert(arr.trustedIndex().thrown); | ||
assert(arr. systemIndex().thrown); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// REQUIRED_ARGS: -boundscheck=safeonly | ||
// PERMUTE_ARGS: -inline -g -O | ||
|
||
import core.exception : RangeError; | ||
|
||
// Check for RangeError is thrown | ||
bool thrown(T)(lazy T cond) | ||
{ | ||
import core.exception; | ||
bool f = false; | ||
try { cond(); } catch (RangeError e) { f = true; } | ||
return f; | ||
} | ||
|
||
@safe int safeIndex (int[] arr) { return arr[2]; } | ||
@trusted int trustedIndex(int[] arr) { return arr[2]; } | ||
@system int systemIndex (int[] arr) { return arr[2]; } | ||
|
||
void main() | ||
{ | ||
int[3] data = [1,2,3]; | ||
int[] arr = data[0..2]; | ||
|
||
assert(arr. safeIndex().thrown); | ||
assert(arr.trustedIndex() == 3); | ||
assert(arr. systemIndex() == 3); | ||
} |