次のように共用体型を宣言します。
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
したがって、派生型にはプラグマ Convention が適用されているように見えますが、Unchecked_Union は適用されていません。Record_Type
プリミティブ操作が既に定義されているため (Integer2
は別のパッケージで定義されています) 、派生型に再度適用することはできません。
これは正しい動作ですか、それとも GNAT のバグですか? 新しい型が Unchecked_Union プラグマを継承するように、Unchecked_Union 型から正しく派生させるにはどうすればよいですか?
GNAT バージョン: GNAT GPL 2012 (20120509)。