This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Ada] Array components of discriminated records with packed parent types


If a component of a record subtype is constrained by discriminants, and the
component of the parent type is a packed array type, the record subtype and
its components might not be frozen explicitly, in which case the packed array
type of the component type must be constructed explicitly when the component
is created.

Compiling p.adb must yield the following warning:

    p.ads:15:04: warning: pragma Pack causes component size to be 15
    p.ads:15:04: warning: use Component_Size to set desired value

---
package p is

   type Int16 is new Short_Integer;
   for Int16'Size use 16;

   Int16_Last : constant Int16 := Int16'Last;

   subtype Pos16 is Int16 range 1 .. Int16_Last;
   subtype Nat16 is Int16 range 0 .. Int16_Last;
 
   type Abstract_Association_Server is abstract tagged limited null record;

   type Association_Access_At is
         array (Pos16 range <>, Pos16 range <>) of Nat16;
   pragma Pack (Association_Access_At);

   protected type Association_Buffering (Nr_O1 : Nat16; Nr_O2 : Nat16) is
   private
      Association_Access : Association_Access_At (1 .. Nr_O1, 1 .. Nr_O2);
      Created : Boolean := False;
   end Association_Buffering;

   type Association_Server
            (Nr_Associations : Pos16; Nr_O1 : Nat16; Nr_O2 : Nat16)
      is abstract new Abstract_Association_Server
      with record
         Association_Buffer : Association_Buffering (Nr_O1, Nr_O2);
      end record;
end p;
--
package body p is

   protected body Association_Buffering is

      procedure Create is
      begin
         Created := True;
      end Create;

   end Association_Buffering;

end p;

Tested on x86_64-pc-linux-gnu, committed on trunk

2013-04-23  Ed Schonberg  <schonberg@adacore.com>

	* sem_ch3.adb: Add exp_pakd to context.
	(Constrain_Component_Type): If the component of the parent is
	packed, and the record subtype being built is already frozen,
	as is the case for an itype, the component type itself will not
	be frozen, and the packed array type for it must be constructed
	explicitly.

Attachment: difs
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]