为什么 Ada 不引发约束错误?
Why is Ada not raising a constraint error?
我有以下匿名子类型的声明:
testConstraint : Integer Range -5 .. 5;
然后以后赋值的时候:
testConstraint := -6;
为什么我没有收到 Constraint_Error
?
其他详细信息:
- 有问题的代码文件中没有
pragma suppress
语句(尽管在通过 with
; 添加的文件中有一些语句
- 构建是通过
gprbuild
使用 GPS 5.0.2 和 GNAT Pro 6.4.2 完成的
- 使用了以下标志:
-gnatf -gnatp -gnat2012 -d
- .gpr 文件中还有来自 "external" 的标志 - 但我不知道这些标志在哪里或这意味着什么。
正如@Timur 和@theMayer 所说:
-gnatp
suppresses all checks.
来自文档:
-gnatp
This switch causes the unit to be compiled as though pragma Suppress (All_checks) had been present in the source. Validity checks
are also eliminated (in other words -gnatp also implies -gnatVn). Use
this switch to improve the performance of the code at the expense of
safety in the presence of invalid data or program bugs.
禁止所有检查是一个非常糟糕的主意。如果您已经证明不需要检查(例如通过使用 SPARK),您可以针对特定单位执行此操作, 和 您已经测量到抑制所有检查可以提高性能你需要的。
解决方案是使用添加编译器标志 -gnat-p
(然后 - 如果满足要求 - 禁止检查单个文件)。
我有以下匿名子类型的声明:
testConstraint : Integer Range -5 .. 5;
然后以后赋值的时候:
testConstraint := -6;
为什么我没有收到 Constraint_Error
?
其他详细信息:
- 有问题的代码文件中没有
pragma suppress
语句(尽管在通过with
; 添加的文件中有一些语句
- 构建是通过
gprbuild
使用 GPS 5.0.2 和 GNAT Pro 6.4.2 完成的
- 使用了以下标志:
-gnatf -gnatp -gnat2012 -d
- .gpr 文件中还有来自 "external" 的标志 - 但我不知道这些标志在哪里或这意味着什么。
正如@Timur 和@theMayer 所说:
-gnatp
suppresses all checks.
来自文档:
-gnatp
This switch causes the unit to be compiled as though pragma Suppress (All_checks) had been present in the source. Validity checks are also eliminated (in other words -gnatp also implies -gnatVn). Use this switch to improve the performance of the code at the expense of safety in the presence of invalid data or program bugs.
禁止所有检查是一个非常糟糕的主意。如果您已经证明不需要检查(例如通过使用 SPARK),您可以针对特定单位执行此操作, 和 您已经测量到抑制所有检查可以提高性能你需要的。
解决方案是使用添加编译器标志 -gnat-p
(然后 - 如果满足要求 - 禁止检查单个文件)。