]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Add ctor call after address clause
authorAlexandre Oliva <oliva@adacore.com>
Wed, 1 Oct 2025 14:59:18 +0000 (11:59 -0300)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Mon, 3 Nov 2025 14:15:15 +0000 (15:15 +0100)
An object initialized by a C++-imported constructor call has the
constructor function call transformed into a procedure call, and the
call is inserted after the object declaration.

If the object has say an address clause, that transformation separates
the declaration from the address clause, causing the translation of
the call to fail.

Keep such clauses next to the declaration by inserting the constructor
procedure call after them.

gcc/ada/ChangeLog:

* exp_ch3.adb (Expand_N_Object_Declaration): Insert ctor call
after representation clauses.

gcc/ada/exp_ch3.adb

index 60224c19b19bbbc88d32ee50ad3681ca1a77c824..482084cdebc35f200bfbd60fec13b0d49935bbb2 100644 (file)
@@ -8286,6 +8286,16 @@ package body Exp_Ch3 is
                   Set_Must_Not_Freeze (Id_Ref);
                   Set_Assignment_OK (Id_Ref);
 
+                  --  Avoid separating an object declaration from
+                  --  its representation clauses.
+
+                  while Present (Next (Init_After))
+                    and then Nkind (Next (Init_After)) in
+                               N_Attribute_Definition_Clause
+                  loop
+                     Init_After := Next (Init_After);
+                  end loop;
+
                   Insert_Actions_After (Init_After,
                     Build_Initialization_Call (N, Id_Ref, Typ,
                       Constructor_Ref => Expr));