Param_Level :=
New_Occurrence_Of (Extra_Accessibility (Param_Ent), Loc);
- Type_Level :=
- Make_Integer_Literal (Loc, Deepest_Type_Access_Level (Typ));
+ -- Use the dynamic accessibility parameter for the function's result
+ -- when one has been created instead of statically referring to the
+ -- deepest type level so as to appropriatly handle the rules for
+ -- RM 3.10.2 (10.1/3).
+
+ if Ekind_In (Scope (Param_Ent), E_Function,
+ E_Operator,
+ E_Subprogram_Type)
+ and then Present (Extra_Accessibility_Of_Result (Scope (Param_Ent)))
+ then
+ Type_Level :=
+ New_Occurrence_Of
+ (Extra_Accessibility_Of_Result (Scope (Param_Ent)), Loc);
+ else
+ Type_Level :=
+ Make_Integer_Literal (Loc, Deepest_Type_Access_Level (Typ));
+ end if;
-- Raise Program_Error if the accessibility level of the access
-- parameter is deeper than the level of the target access type.
return False;
end Has_Unconstrained_Access_Discriminant_Component;
- Feature_Disabled : constant Boolean := True;
- -- Temporary
+ Disable_Coextension_Cases : constant Boolean := True;
+ -- Flag used to temporarily disable a "True" result for types with
+ -- access discriminants and related coextension cases.
-- Start of processing for Needs_Result_Accessibility_Level
if not Present (Func_Typ) then
return False;
- elsif Feature_Disabled then
- return False;
-
-- False if not a function, also handle enum-lit renames case
elsif Func_Typ = Standard_Void_Type
elsif Ada_Version < Ada_2012 then
return False;
- elsif Ekind (Func_Typ) = E_Anonymous_Access_Type
- or else Is_Tagged_Type (Func_Typ)
- then
- -- In the case of, say, a null tagged record result type, the need
- -- for this extra parameter might not be obvious. This function
- -- returns True for all tagged types for compatibility reasons.
- -- A function with, say, a tagged null controlling result type might
- -- be overridden by a primitive of an extension having an access
- -- discriminant and the overrider and overridden must have compatible
- -- calling conventions (including implicitly declared parameters).
- -- Similarly, values of one access-to-subprogram type might designate
- -- both a primitive subprogram of a given type and a function
- -- which is, for example, not a primitive subprogram of any type.
- -- Again, this requires calling convention compatibility.
- -- It might be possible to solve these issues by introducing
- -- wrappers, but that is not the approach that was chosen.
+ -- Handle the situation where a result is an anonymous access type
+ -- RM 3.10.2 (10.3/3).
+
+ elsif Ekind (Func_Typ) = E_Anonymous_Access_Type then
+ return True;
+
+ -- The following cases are related to coextensions and do not fully
+ -- cover everything mentioned in RM 3.10.2 (12) ???
+
+ -- Temporarily disabled ???
+
+ elsif Disable_Coextension_Cases then
+ return False;
+
+ -- In the case of, say, a null tagged record result type, the need for
+ -- this extra parameter might not be obvious so this function returns
+ -- True for all tagged types for compatibility reasons.
+
+ -- A function with, say, a tagged null controlling result type might
+ -- be overridden by a primitive of an extension having an access
+ -- discriminant and the overrider and overridden must have compatible
+ -- calling conventions (including implicitly declared parameters).
+
+ -- Similarly, values of one access-to-subprogram type might designate
+ -- both a primitive subprogram of a given type and a function which is,
+ -- for example, not a primitive subprogram of any type. Again, this
+ -- requires calling convention compatibility. It might be possible to
+ -- solve these issues by introducing wrappers, but that is not the
+ -- approach that was chosen.
+ elsif Is_Tagged_Type (Func_Typ) then
return True;
elsif Has_Unconstrained_Access_Discriminants (Func_Typ) then