This patch corrects an omission on the legality check for allocators with
a qualified expression when the expression is of a limited type. The check
must be performed after the expression is fully resolved, to handle properly
complex overloading cases such as indexings of parameterless functions that
return arrays.

ACATS test B750a04.

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

2015-10-27  Ed Schonberg  <schonb...@adacore.com>

        * sem_ch4.adb (Analyze_Allocator): Do not perform legality check
        on allocators for limited objects in a qualified expression,
        because expression has not been resolved.
        * sem_res.adb (Resolve_Allocator): Perform check on legality of
        limited objects after resolution.  Add sem_ch3.adb to context.

Index: sem_res.adb
===================================================================
--- sem_res.adb (revision 229421)
+++ sem_res.adb (working copy)
@@ -57,6 +57,7 @@
 with Sem_Attr; use Sem_Attr;
 with Sem_Cat;  use Sem_Cat;
 with Sem_Ch4;  use Sem_Ch4;
+with Sem_Ch3;  use Sem_Ch3;
 with Sem_Ch6;  use Sem_Ch6;
 with Sem_Ch8;  use Sem_Ch8;
 with Sem_Ch13; use Sem_Ch13;
@@ -4680,6 +4681,22 @@
          Check_Non_Static_Context (Expression (E));
          Check_Unset_Reference (Expression (E));
 
+         --  Allocators generated by the build-in-place expansion mechanism
+         --  are explicitly marked as coming from source but do not need to be
+         --  checked for limited initialization. To exclude this case, ensure
+         --  that the parent of the allocator is a source node.
+
+         if Is_Limited_Type (Etype (E))
+           and then Comes_From_Source (N)
+           and then Comes_From_Source (Parent (N))
+           and then not In_Instance_Body
+         then
+            if not OK_For_Limited_Init (Etype (E), Expression (E)) then
+               Error_Msg_N ("initialization not allowed for limited types", N);
+               Explain_Limited_Type (Etype (E), N);
+            end if;
+         end if;
+
          --  A qualified expression requires an exact match of the type.
          --  Class-wide matching is not allowed.
 
Index: sem_ch4.adb
===================================================================
--- sem_ch4.adb (revision 229413)
+++ sem_ch4.adb (working copy)
@@ -549,22 +549,6 @@
          Type_Id := Etype (E);
          Set_Directly_Designated_Type (Acc_Type, Type_Id);
 
-         --  Allocators generated by the build-in-place expansion mechanism
-         --  are explicitly marked as coming from source but do not need to be
-         --  checked for limited initialization. To exclude this case, ensure
-         --  that the parent of the allocator is a source node.
-
-         if Is_Limited_Type (Type_Id)
-           and then Comes_From_Source (N)
-           and then Comes_From_Source (Parent (N))
-           and then not In_Instance_Body
-         then
-            if not OK_For_Limited_Init (Type_Id, Expression (E)) then
-               Error_Msg_N ("initialization not allowed for limited types", N);
-               Explain_Limited_Type (Type_Id, N);
-            end if;
-         end if;
-
          --  A qualified expression requires an exact match of the type,
          --  class-wide matching is not allowed.
 

Reply via email to