]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Improved support for incomplete parameter types
authorSteve Baird <baird@adacore.com>
Thu, 5 Sep 2024 20:42:20 +0000 (13:42 -0700)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Tue, 8 Oct 2024 08:37:13 +0000 (10:37 +0200)
Fix two bugs uncovered by a recent ACATS test C3A1005: a freezing problem
and a case where a user-defined equality function for an incomplete type
was incorrectly hidden from use-clause visibility by the "corresponding"
predefined op (which doesn't actually exist).

gcc/ada/ChangeLog:

* sem_ch6.adb (Analyze_Subprogram_Body_Helper): Don't freeze here
if Has_Delayed_Freeze returns True.
* sem_type.adb (Valid_Equality_Arg): Treat an incomplete type like
a limited type because neither has an implicitly-defined equality
primitive.
(Covers): If either argument is an incomplete type
whose full view is available, then look through to the full view.
* sem_res.adb (Resolve_Actuals): If the actual parameter type is
complete and the formal parameter type is not, then update the
formal parameter type to use the complete view.

gcc/ada/sem_ch6.adb
gcc/ada/sem_res.adb
gcc/ada/sem_type.adb

index c200871b852002dbc43f2f4a9633f36c358616b1..8cf191d751bd4c65cce280c4c363699a88cad54d 100644 (file)
@@ -4135,7 +4135,9 @@ package body Sem_Ch6 is
                Set_Is_Public (Body_Id, False);
             end if;
 
-            Freeze_Before (N, Body_Id);
+            if not Has_Delayed_Freeze (Body_Id) then
+               Freeze_Before (N, Body_Id);
+            end if;
          end if;
 
          if Nkind (N) /= N_Subprogram_Body_Stub then
index c8652eed79636a52cc3175c16c0fbce2ff353e6c..6b673a9c1987eb05b3bba601cb95c6bed6655257 100644 (file)
@@ -4658,6 +4658,15 @@ package body Sem_Res is
             A_Typ := Etype (A);
             F_Typ := Etype (F);
 
+            --  If A_Typ is complete and F_Typ is not, then adjust F_Typ
+
+            if Ekind (F_Typ) = E_Incomplete_Type
+              and then Present (Full_View (F_Typ))
+              and then not Is_Incomplete_Type (A_Typ)
+            then
+               F_Typ := Full_View (F_Typ);
+            end if;
+
             --  An actual cannot be an untagged formal incomplete type
 
             if Ekind (A_Typ) = E_Incomplete_Type
index b76c6efd9d9d41f94008684bbcfc07b0ebfa0a02..75e7dafbc6045e62d558e662e542e4ca8e8d5202 100644 (file)
@@ -1228,6 +1228,18 @@ package body Sem_Type is
          return Has_Non_Limited_View (T2)
            and then Covers (T1, Get_Full_View (Non_Limited_View (T2)));
 
+      --  Coverage for incomplete types
+
+      elsif Ekind (T1) = E_Incomplete_Type
+        and then Present (Full_View (T1))
+      then
+         return Covers (Full_View (T1), T2);
+
+      elsif Ekind (T2) = E_Incomplete_Type
+        and then Present (Full_View (T2))
+      then
+         return Covers (T1, Full_View (T2));
+
       --  Ada 2005 (AI-412): Coverage for regular incomplete subtypes
 
       elsif Ekind (T1) = E_Incomplete_Subtype then
@@ -3586,6 +3598,9 @@ package body Sem_Type is
       if Is_Anonymous_Access_Type (T) then
          return Ada_Version >= Ada_2005;
 
+      elsif Is_Incomplete_Type (T) then
+         return False;
+
       elsif not Is_Limited_Type (T) then
          return True;