+2018-11-14 Ed Schonberg <schonberg@adacore.com>
+
+ * exp_ch3.adb: (Expand_N_Object_Declaration): If the expression
+ is a limited aggregate its resolution is delayed until the
+ object declaration is expanded.
+ * sem_ch3.adb: (Analyze_Object_Declaration): If the expression
+ is a limited aggregate and the declaration has a following
+ address clause indicate that resolution of the aggregate (which
+ must be built in place) must be delayed.
+
2018-11-14 Bob Duff <duff@adacore.com>
* sem_attr.adb (To_Address): Simplify setting of
-- thus avoid creating a temporary.
if Is_Delayed_Aggregate (Expr_Q) then
+
+ -- An aggregate that must be built in place is not resolved
+ -- and expanded until the enclosing construct is expanded.
+ -- This will happen when the aggregqte is limited and the
+ -- declared object has a following address clause.
+
+ if Is_Limited_Type (Typ) and then not Analyzed (Expr) then
+ Resolve (Expr, Typ);
+ end if;
+
Convert_Aggr_In_Object_Decl (N);
-- Ada 2005 (AI-318-02): If the initialization expression is a call
-- Given that the type is limited we cannot perform a copy. If
-- Expr_Q is the reference to a variable we mark the variable
-- as OK_To_Rename to expand this declaration into a renaming
- -- declaration (see bellow).
+ -- declaration (see below).
if Is_Entity_Name (Expr_Q) then
Set_OK_To_Rename (Entity (Expr_Q));
then
Set_Etype (E, T);
+ -- If the aggregate is limited it will be built in place,
+ -- and its expansion is deferred until the object declaration
+ -- is expanded.
+
+ if Is_Limited_Type (T) then
+ Set_Expansion_Delayed (E);
+ end if;
+
else
-- If the expression is a formal that is a "subprogram pointer"
+2018-11-14 Ed Schonberg <schonberg@adacore.com>
+
+ * gnat.dg/limited_aggr.adb, gnat.dg/limited_aggr.ads: New
+ testcase.
+
2018-11-14 Justin Squirek <squirek@adacore.com>
* gnat.dg/enum5.adb: New testcase.
--- /dev/null
+-- { dg-do compile }
+
+package body Limited_Aggr is
+ procedure Dummy is null;
+end Limited_Aggr;
--- /dev/null
+package Limited_Aggr is
+ type R is limited record
+ F1, F2 : Integer;
+ end record;
+ X : array (1..2) of integer;
+ Y : R := (-111, -222);
+ for Y'Address use X'Address;
+
+ procedure Dummy;
+end Limited_Aggr;