This fixes an assertion failure for the Finalizable aspect applied on a tagged 
type with discriminant-dependent component.

Tested on x86-64/Linux, applied on the mainline and 15 branch.


2025-07-01  Eric Botcazou  <ebotca...@adacore.com>

        PR ada/120705
        * exp_ch6.adb (Needs_BIP_Collection): Always return False if the
        type has relaxed finalization.


2025-07-01  Eric Botcazou  <ebotca...@adacore.com>

        * gnat.dg/specs/finalizable2.ads: New test.

-- 
Eric Botcazou
diff --git a/gcc/ada/exp_ch6.adb b/gcc/ada/exp_ch6.adb
index 26302baad64..621619220a0 100644
--- a/gcc/ada/exp_ch6.adb
+++ b/gcc/ada/exp_ch6.adb
@@ -9575,9 +9575,8 @@ package body Exp_Ch6 is
       --  such build-in-place functions, primitive or not.
 
       return not Restriction_Active (No_Finalization)
-        and then ((Needs_Finalization (Typ)
-                    and then not Has_Relaxed_Finalization (Typ))
-                  or else Is_Tagged_Type (Typ))
+        and then (Needs_Finalization (Typ) or else Is_Tagged_Type (Typ))
+        and then not Has_Relaxed_Finalization (Typ)
         and then not Has_Foreign_Convention (Typ);
    end Needs_BIP_Collection;
 
-- { dg-do compile }
-- { dg-options "-gnatX0" }

package Finalizable2 is

   type Root is abstract tagged limited null record
      with Finalizable => (Initialize => Initialize);

   procedure Initialize (this : in out Root) is abstract;

   type Ext (L : Natural) is new Root with record
      A : String (1 .. L);
   end record;

   overriding procedure Initialize (this : in out Ext) is null;

   function Make return Ext is (L => 3, A => "asd");

   Obj : Ext := Make;

end Finalizable2;

Reply via email to