]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Crash on C++ constructor of private type
authorJavier Miranda <miranda@adacore.com>
Mon, 8 May 2023 19:10:56 +0000 (19:10 +0000)
committerMarc Poulhiès <poulhies@adacore.com>
Thu, 15 Jun 2023 07:59:33 +0000 (09:59 +0200)
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.

gcc/ada/sem_util.adb

index 3fd3eb45f334fe9186f41372ca95a269d20c23ae..3a64047d45c1829f9ff04d211b2a2fc15affd6fe 100644 (file)
@@ -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;