Ada use of aspect Default_Component_Value on an array, with Pragma Pack

Viewed 76

I'm using gnat gcc 11.1, and wanted to know if someone can explain to me this behavior:

This is my code:

with Ada.Text_IO;           use Ada.Text_IO;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
pragma Ada2012;

procedure Hello is
   type bool_arr is array (Integer range 1 .. Integer'Size) of Boolean with
      Default_Component_Value => True;
   pragma Pack (bool_arr);

   test : bool_arr;

   procedure P is
      idx   : String           := "index ";
      strg  : Unbounded_String := To_Unbounded_String (idx);
      strg2 : Unbounded_String;
   begin
      for I in test'range loop
         Append (strg, I'Image);
         Append (strg2, " " & test (I)'Image);
      end loop;
      Put_Line (To_string (strg));
      Put_Line (To_String (strg2));

   end P;
begin
   P;
end Hello;

As Out I get this :

Hello, world! index 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 TRUE TRUE FALSE FALSE FALSE TRUE FALSE TRUE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE

Which is not what I wanted, by setting with Default_Component_Value => True.

If I comment out the Pragma Pack(bool_arr), then I get this:

Hello, world! index 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE

Thanks for the help.

1 Answers

Looks like a bug in GNAT, I'm sorry to say.

If I explicitly use the Default_Component_Value, by declaring

   test : bool_arr := (others => <>);

all components are True, as expected.

Related