https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123589

            Bug ID: 123589
           Summary: [GNAT 13/14/15/16] Default_Component_Value does not
                    correctly initialize boolean arrays with Pack aspect
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: ada
          Assignee: unassigned at gcc dot gnu.org
          Reporter: lisa at felidae dot bam.moe
                CC: dkm at gcc dot gnu.org
  Target Milestone: ---

The following program will print "bug in P" on various GCC versions and
platforms (detailed below):

```
with Ada.Text_IO; use Ada.Text_IO;

procedure Main is
   type Bool_Packed_Array is
     array (Positive range 1 .. 20, Positive range 1 .. 20) of Boolean
   with Default_Component_Value => False, Pack;

   type Bool_Nonpacked_Array is
     array (Positive range 1 .. 20, Positive range 1 .. 20) of Boolean
   with Default_Component_Value => False;

   P  : Bool_Packed_Array;
   NP : Bool_Nonpacked_Array;
begin
   if (for all E of P => E = False) then
      Put_Line ("P initialized correctly");
   else
      Put_Line ("bug in P");
   end if;

   if (for all E of NP => E = False) then
      Put_Line ("NP initialized correctly");
   else
      Put_Line ("bug in NP");
   end if;
end Main;
```

This prints "bug in P" on the following configurations:
- GCC 16.0.0 20251216 (commit 1d29b6856238ead0c26ce1cb65122e4deef9af00) on
x86_64-w64-mingw32 (Note: This compiler is slightly modified in that I had to
manually add the patches from the MSYS2 project to get it to build)

- GCC 15.2.0 on x86_64-w64-mingw32 (MSYS2)

- GCC 14.2.0 on x86_64-linux-gnu (Debian 13)

- GCC 13.3.0 on aarch64-linux-gnu (Debian 13)

For the compiler flags I only used `-gnat2022`. Adding `-gnatwa` on GCC 16
raises no warnings.

Someone on StackOverflow has already posted about this bug in January of 2022:
https://stackoverflow.com/questions/70732217/ada-use-of-aspect-default-component-value-on-an-array-with-pragma-pack

It seems to be sensitive to random changes, e.g. adding extra Put_Line
statements or fiddling with the array size sometimes makes it go away.

Initializing the array at declaration fixes it, it's just
Default_Component_Value that doesn't work.
  • [Bug ada/123589] New: [GNAT 13/1... lisa at felidae dot bam.moe via Gcc-bugs

Reply via email to