Siz := Aggregate_Size;
+ ---------------------
+ -- Empty function --
+ ---------------------
+
if Ekind (Entity (Empty_Subp)) = E_Function
and then Present (First_Formal (Entity (Empty_Subp)))
then
Append (Init_Stat, Aggr_Code);
- -- Size is dynamic: Create declaration for object, and intitialize
+ -- Size is dynamic: Create declaration for object, and initialize
-- with a call to the null container, or an assignment to it.
else
Append (Init_Stat, Aggr_Code);
end if;
+ -- Report warning on infinite recursion if an empty container aggregate
+ -- appears in the return statement of its Empty function.
+
+ if Ekind (Entity (Empty_Subp)) = E_Function
+ and then Nkind (Parent (N)) = N_Simple_Return_Statement
+ and then Is_Empty_List (Expressions (N))
+ and then Is_Empty_List (Component_Associations (N))
+ and then Entity (Empty_Subp) = Current_Scope
+ then
+ Error_Msg_Warn := SPARK_Mode /= On;
+ Error_Msg_N
+ ("!empty aggregate returned by the empty function of a container"
+ & " aggregate<<<", Parent (N));
+ Error_Msg_N
+ ("\this will result in infinite recursion??", Parent (N));
+ end if;
+
---------------------------
-- Positional aggregate --
---------------------------
Resolve_Container_Aggregate (N, Typ);
+ -- Check Ada 2022 empty aggregate [] initializing a record type that has
+ -- aspect aggregate; the empty aggregate will be expanded into a call to
+ -- the empty function specified in the aspect aggregate.
+
+ elsif Has_Aspect (Typ, Aspect_Aggregate)
+ and then Ekind (Typ) = E_Record_Type
+ and then Is_Homogeneous_Aggregate (N)
+ and then Is_Empty_List (Expressions (N))
+ and then Is_Empty_List (Component_Associations (N))
+ and then Ada_Version >= Ada_2022
+ then
+ Resolve_Container_Aggregate (N, Typ);
+
elsif Is_Record_Type (Typ) then
Resolve_Record_Aggregate (N, Typ);
if Present (Add_Unnamed_Subp)
and then No (New_Indexed_Subp)
+ and then Present (Etype (Add_Unnamed_Subp))
and then Etype (Add_Unnamed_Subp) /= Any_Type
then
declare
Op_Name := Chars (First (Choices (Assoc)));
-- When verifying the consistency of aspects between the freeze point
- -- and the end of declarqtions, we use a copy which is not analyzed
+ -- and the end of declarations, we use a copy which is not analyzed
-- yet, so do it now.
Subp_Id := Expression (Assoc);