From: Javier Miranda Date: Mon, 8 May 2023 19:10:56 +0000 (+0000) Subject: ada: Crash on C++ constructor of private type X-Git-Tag: basepoints/gcc-15~8296 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=63c8e3a136860f967ba29ba64ef261f94ceb6fc8;p=thirdparty%2Fgcc.git ada: Crash on C++ constructor of private type The compiler crashes compiling a function that has pragma CPP_constructor when its return type is a private type. gcc/ada/ * sem_util.adb (Is_CPP_Constructor_Call): Add missing support for calls to functions returning a private type. --- diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb index 3fd3eb45f334..3a64047d45c1 100644 --- a/gcc/ada/sem_util.adb +++ b/gcc/ada/sem_util.adb @@ -16153,9 +16153,25 @@ package body Sem_Util is ----------------------------- function Is_CPP_Constructor_Call (N : Node_Id) return Boolean is + Ret_Typ : Entity_Id; + begin - return Nkind (N) = N_Function_Call - and then Is_CPP_Class (Etype (Etype (N))) + if Nkind (N) /= N_Function_Call then + return False; + end if; + + Ret_Typ := Base_Type (Etype (N)); + + if Is_Class_Wide_Type (Ret_Typ) then + Ret_Typ := Root_Type (Ret_Typ); + end if; + + if Is_Private_Type (Ret_Typ) then + Ret_Typ := Underlying_Type (Ret_Typ); + end if; + + return Present (Ret_Typ) + and then Is_CPP_Class (Ret_Typ) and then Is_Constructor (Entity (Name (N))) and then Is_Imported (Entity (Name (N))); end Is_CPP_Constructor_Call;