Establish_Transient_Scope
(Call_Node, Needs_Secondary_Stack (Etype (Call_Node)));
end if;
+
+ -- Functions returning noncontrolled objects that may be subject to
+ -- user-defined indexing also need special attention. The problem
+ -- is that, when a call to such a function is directly passed as an
+ -- actual in a call to the Constant_Indexing function, the latter
+ -- call effectively binds the lifetime of the actual to that of its
+ -- return value, thus extending it beyond the call. This cannot be
+ -- directly supported by code generators, for which the lifetime of
+ -- temporaries created for actuals ends immediately after the call.
+ -- Therefore we force the creation of a temporary in this case, as
+ -- the above code would have done in the controlled case; note that,
+ -- in this latter case, the temporary cannot be finalized just after
+ -- the call as would naturally be done, and Is_Finalizable_Transient
+ -- also has a special processing for it (see Is_Indexed_Container).
+
+ elsif Nkind (Call_Node) = N_Function_Call
+ and then Nkind (Parent (Call_Node)) = N_Function_Call
+ then
+ declare
+ Aspect : constant Node_Id :=
+ Find_Value_Of_Aspect
+ (Etype (Call_Node), Aspect_Constant_Indexing);
+
+ begin
+ if Present (Aspect)
+ and then Is_Entity_Name (Name (Parent (Call_Node)))
+ and then Entity (Name (Parent (Call_Node))) = Entity (Aspect)
+ then
+ -- Resolution is now finished, make sure we don't start
+ -- analysis again because of the duplication.
+
+ Set_Analyzed (Call_Node);
+
+ Remove_Side_Effects (Call_Node);
+ end if;
+ end;
end if;
end Expand_Call_Helper;