GNAT 允许以下代码,因为 Random(Generator, First, Last)
是在运行时实现的,但它不是 Ada 2012 的一部分。我能否导致它生成编译错误,因为它应该不可用?
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Numerics.Discrete_Random;
procedure Main is
package Positive_Random is new Ada.Numerics.Discrete_Random
(Result_Subtype => Positive);
Generator : Positive_Random.Generator;
-- This should fail, since function isn't part of Ada 2012.
Value : Positive := Positive_Random.Random (Generator, 1, 10);
begin
Put_Line (Value'Image);
end Main;
这是我的 gpr 文件:
project Default is
for Source_Dirs use ("src");
for Object_Dir use "obj";
for Main use ("main.adb");
package Compiler is
for Switches ("ada") use ("-gnat12");
end Compiler;
end Default;
最佳答案
在我看来,the standard way这样做是添加 a global restriction :
pragma Restrictions (No_Implementation_Identifiers);
No_Implementation_Identifiers
There are no usage names that denote declarations with implementation-defined identifiers that occur within language-defined packages or instances of language-defined generic packages.
但这在 GNAT Community Edition 2021 中不起作用(我想在 GCC 11 中也不行)。
您可以创建自定义 GNAT 运行时并删除此子程序或使用方面 Implementation_Defined
标记它以使限制生效。
关于ada - 防止在 GNAT 中使用 Ada 202x,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68605628/