我声明一个这样的联合类型:
type Access_Kind is (Named, Indexed);
type Array_Type is array (0 .. 1) of Integer;
type Record_Type (Kind : Access_Kind := Access_Kind'First) is record
case Kind is
when Named =>
X, Y : Integer;
when Indexed =>
S : Array_Type;
end case;
end record;
pragma Unchecked_Union (Record_Type);
pragma Convention (C_Pass_By_Copy, Record_Type);
function Create (X, Y : Integer) return Record_Type;
现在,当我尝试创建派生类型时:
type Integer2 is new Record_Type;
GNAT 给了我以下警告:
warning: in instantiation at line [pragma Convention...]
warning: variant record has no direct equivalent in C
warning: use of convention for type "Integer2" is dubious
所以看起来 pragma 约定适用于派生类型,但 Unchecked_Union 不是。我无法再次将其应用于派生类型,因为Record_Type
已经定义了原始操作(Integer2
在另一个包中定义)。
这是正确的行为还是 GNAT 错误?如何正确地从 Unchecked_Union 类型派生,以便新类型继承 Unchecked_Union pragma?
GNAT 版本:GNAT GPL 2012 (20120509)。