From: Denis Mazzucato Date: Thu, 18 Dec 2025 12:34:18 +0000 (+0100) Subject: ada: Fix crash on legality check for initialization of implicit constructor X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=197dfdca778234286dfcb8b5cb91af93e24e4341;p=thirdparty%2Fgcc.git ada: Fix crash on legality check for initialization of implicit constructor This patch fixes a crash occurring during the legality check of the Initialize aspect when the constructor is implicitly created by the compiler, e.g., the default copy constructor. In such case, Corresponding_Spec is not available, the Specification field must be used instead. gcc/ada/ChangeLog: * sem_ch13.adb (Check_Constructor_Initialization_Expression): The first parameter of an implicit constructor comes from Specification, not Corresponding_Spec. --- diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb index 06a98e4305a..38732cf58be 100644 --- a/gcc/ada/sem_ch13.adb +++ b/gcc/ada/sem_ch13.adb @@ -3305,8 +3305,7 @@ package body Sem_Ch13 is procedure Check_Constructor_Initialization_Expression (Expr : Node_Id; Aspect_Name : String) is - First_Parameter : constant Entity_Id := - First_Entity (Corresponding_Spec (N)); + First_Parameter : Entity_Id; -- Flag error if N refers to the forbidden entity function Check_Node_For_Bad_Reference @@ -3324,7 +3323,7 @@ package body Sem_Ch13 is then Error_Msg_N ("constructed object referenced in " & - Aspect_Name & " aspect_specification", N); + Aspect_Name & " aspect_specification", N); end if; return OK; @@ -3333,6 +3332,16 @@ package body Sem_Ch13 is procedure Check_Tree_For_Bad_Reference is new Traverse_Proc (Check_Node_For_Bad_Reference); begin + -- If coming from an implicit constructor, the Self parameter + -- is retrieved via the specification's defining unit name. + + if Acts_As_Spec (N) then + First_Parameter := + First_Entity (Defining_Unit_Name (Specification (N))); + else + First_Parameter := First_Entity (Corresponding_Spec (N)); + end if; + Check_Tree_For_Bad_Reference (Expr); end Check_Constructor_Initialization_Expression;