为什么 Ada 不引发约束错误?

Why is Ada not raising a constraint error?

我有以下匿名子类型的声明:

testConstraint : Integer Range -5 .. 5;

然后以后赋值的时候:

testConstraint := -6;

为什么我没有收到 Constraint_Error

其他详细信息:

正如@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(然后 - 如果满足要求 - 禁止检查单个文件)。