diff mbox series

[Ada] Ada 2020 AI12-0401 Renaming of qualified expression of variable

Message ID 20201126084101.GA20700@adacore.com
State New
Headers show
Series [Ada] Ada 2020 AI12-0401 Renaming of qualified expression of variable | expand

Commit Message

Pierre-Marie de Rodat Nov. 26, 2020, 8:41 a.m. UTC
This AI restricts renaming of a qualified expression to cases where the
operand is a constant, or the target subtype statically matches the
nominal subtype of the operand, or is unconstrained with no predicates.

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

gcc/ada/

	* sem_ch8.adb (Analyze_Object_Renaming): Check for AI12-0401.
diff mbox series

Patch

diff --git a/gcc/ada/sem_ch8.adb b/gcc/ada/sem_ch8.adb
--- a/gcc/ada/sem_ch8.adb
+++ b/gcc/ada/sem_ch8.adb
@@ -1038,6 +1038,22 @@  package body Sem_Ch8 is
             Mark_Ghost_Renaming (N, Entity (Nam));
          end if;
 
+         --  Check against AI12-0401 here before Resolve may rewrite Nam and
+         --  potentially generate spurious warnings.
+
+         if Nkind (Nam) = N_Qualified_Expression
+           and then Is_Variable (Expression (Nam))
+           and then not
+             (Subtypes_Statically_Match (T, Etype (Expression (Nam)))
+                or else
+              Subtypes_Statically_Match (Base_Type (T), Etype (Nam)))
+         then
+            Error_Msg_N
+              ("subtype of renamed qualified expression does not " &
+               "statically match", N);
+            return;
+         end if;
+
          Resolve (Nam, T);
 
          --  If the renamed object is a function call of a limited type,