[Ada] Ada 2020 AI12-0401 Renaming of qualified expression of variable
authorArnaud Charlet <charlet@adacore.com>
Wed, 28 Oct 2020 08:55:16 +0000 (04:55 -0400)
committerPierre-Marie de Rodat <derodat@adacore.com>
Thu, 26 Nov 2020 08:40:02 +0000 (03:40 -0500)
gcc/ada/

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

gcc/ada/sem_ch8.adb

index 4c80e02..f78d31a 100644 (file)
@@ -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,