The oversight is that the dynamic accessibility checks should be generated
neither when accessibility checks are disabled, for example by means of the
-gnatp switch, nor when the GNAT restriction No_Dynamic_Accessibility_Checks
is enabled.
gcc/ada/ChangeLog:
* accessibility.adb
(Apply_Accessibility_Check_For_Class_Wide_Return): Do not test if
accessibility checks are suppressed here but...
(Apply_Accessibility_Check_For_Return): ...here instead.
if Ada_Version >= Ada_2005
and then not CodePeer_Mode
and then Tagged_Type_Expansion
- and then not Scope_Suppress.Suppress (Accessibility_Check)
and then
(Is_Class_Wide_Type (Etype (Exp))
or else Nkind (Exp) in
Typ : constant Entity_Id := Etype (Func);
begin
+ -- Return immediately if accessiblity checks are suppressed for Func
+
+ if Accessibility_Checks_Suppressed (Func) then
+ return;
+ end if;
+
-- Ada 2005 (AI95-344): If the result type is class-wide, then insert
-- a check that the level of the return expression's underlying type
-- is not deeper than the level of the master enclosing the function.