https://gcc.gnu.org/g:2aa9e4a4a431d66f5ce474651c04029373181faa

commit r16-1948-g2aa9e4a4a431d66f5ce474651c04029373181faa
Author: Piotr Trojanek <troja...@adacore.com>
Date:   Wed Jun 11 16:41:00 2025 +0200

    ada: Improve retrieval of nominal unconstrained type in extended return
    
    When extended return statement declares object using an explicit subtype
    indication, then it is better to recover the original unconstrained type 
using
    the explicit subtype indication. This appears to be necessary for subtypes 
with
    predicates.
    
    gcc/ada/ChangeLog:
    
            * sem_ch3.adb (Check_Return_Subtype_Indication): Use type from
            explicit subtype indication, when possible.

Diff:
---
 gcc/ada/sem_ch3.adb | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb
index 98a8fa563919..f25941d72a83 100644
--- a/gcc/ada/sem_ch3.adb
+++ b/gcc/ada/sem_ch3.adb
@@ -4204,7 +4204,11 @@ package body Sem_Ch3 is
          --  to recover the nominal unconstrained type.
 
          if Is_Constr_Subt_For_U_Nominal (Obj_Typ) then
-            Obj_Typ := Etype (Obj_Typ);
+            if Nkind (Object_Definition (Obj_Decl)) = N_Subtype_Indication then
+               Obj_Typ := Entity (Subtype_Mark (Object_Definition (Obj_Decl)));
+            else
+               Obj_Typ := Etype (Obj_Typ);
+            end if;
             pragma Assert (not Is_Constrained (Obj_Typ));
          end if;

Reply via email to