]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Missing initialization of aggregate components
authorJavier Miranda <miranda@adacore.com>
Thu, 12 Feb 2026 11:02:57 +0000 (11:02 +0000)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Tue, 26 May 2026 08:38:24 +0000 (10:38 +0200)
When a tagged type conversion is applied to a qualified expression
of an aggregate, at runtime some components are left uninitialized.

gcc/ada/ChangeLog:

* exp_ch4.adb (Expand_N_Type_Conversion): When the operand is a
qualified expression of an aggregate, force its evaluation by
capturing its value in a constant (to ensure full initialization
of the tagged object).

gcc/ada/exp_ch4.adb

index 476508b7449d6e8e072f94f7d99c3b37356eeb73..490ecf8f8340e9818a631f382e920e22c1b92e89 100644 (file)
@@ -12543,6 +12543,17 @@ package body Exp_Ch4 is
          --  Start of processing for Tagged_Conversion
 
          begin
+            --  When the operand is a qualified expression of an aggregate,
+            --  force its evaluation by capturing its value in a constant
+            --  (to ensure full initialization of the tagged object).
+
+            if Nkind (Operand) = N_Qualified_Expression
+              and then Nkind (Expression (Operand)) in N_Aggregate
+                                                     | N_Extension_Aggregate
+            then
+               Force_Evaluation (Operand, Mode => Strict);
+            end if;
+
             --  Handle entities from the limited view
 
             if Is_Access_Type (Operand_Type) then