diff mbox series

[Ada] Errors missed on ACATS test B650007

Message ID 20220518084316.GA3338084@adacore.com
State New
Headers show
Series [Ada] Errors missed on ACATS test B650007 | expand

Commit Message

Pierre-Marie de Rodat May 18, 2022, 8:43 a.m. UTC
This ACATS test shows that we need to call Is_Immutably_Limited_Type
in Analyze_Function_Return and also that we have a latent bug in
Is_Immutably_Limited_Type which shouldn't look through private types.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

	* sem_aux.adb (Is_Immutably_Limited_Type): Do not look through
	private types as per RM 7.5(8.1).
	* sem_ch6.adb (Analyze_Function_Return): Use
	Is_Immutably_Limited_Type as per RM 6.5(5.10).
diff mbox series

Patch

diff --git a/gcc/ada/sem_aux.adb b/gcc/ada/sem_aux.adb
--- a/gcc/ada/sem_aux.adb
+++ b/gcc/ada/sem_aux.adb
@@ -1059,15 +1059,7 @@  package body Sem_Aux is
             end if;
 
          else
-            declare
-               Utyp : constant Entity_Id := Underlying_Type (Btype);
-            begin
-               if No (Utyp) then
-                  return False;
-               else
-                  return Is_Immutably_Limited_Type (Utyp);
-               end if;
-            end;
+            return False;
          end if;
 
       elsif Is_Concurrent_Type (Btype) then


diff --git a/gcc/ada/sem_ch6.adb b/gcc/ada/sem_ch6.adb
--- a/gcc/ada/sem_ch6.adb
+++ b/gcc/ada/sem_ch6.adb
@@ -1566,17 +1566,18 @@  package body Sem_Ch6 is
 
             --  Check RM 6.5 (5.9/3)
 
-            if Has_Aliased then
+            if Has_Aliased and then not Is_Immutably_Limited_Type (R_Type) then
                if Ada_Version < Ada_2012
                  and then Warn_On_Ada_2012_Compatibility
                then
                   Error_Msg_N
-                    ("ALIASED only allowed for limited return objects "
-                     & "in Ada 2012?y?", N);
+                    ("ALIASED only allowed for immutably limited return " &
+                     "objects in Ada 2012?y?", N);
 
-               elsif not Is_Limited_View (R_Type) then
+               else
                   Error_Msg_N
-                    ("ALIASED only allowed for limited return objects", N);
+                    ("ALIASED only allowed for immutably limited return " &
+                     "objects", N);
                end if;
             end if;