This adds the same early return to Check_Return_Construct_Accessibility for
static checks as the one present in Apply_Accessibility_Check_For_Return for
dynamic checks.
Tested on x86-64/Linux, applied on the mainline.
2026-09-22 Eric Botcazou <[email protected]>
* accessibility.adb (Check_Return_Construct_Accessibility): Bail
out for the return synthesized in a function whose body has been
wrapped in a nested _Wrapped_Statements function.
--
Eric Botcazoudiff --git a/gcc/ada/accessibility.adb b/gcc/ada/accessibility.adb
index f7104930e72..42092bebbf9 100644
--- a/gcc/ada/accessibility.adb
+++ b/gcc/ada/accessibility.adb
@@ -2137,11 +2137,14 @@ package body Accessibility is
| N_Simple_Return_Statement);
-- Only perform checks on record types with access discriminants and
- -- functions present in the source.
+ -- functions present in the source, but no checks are needed for the
+ -- return synthesized in a function whose body has been wrapped in a
+ -- nested _Wrapped_Statements function.
if not Is_Record_Type (R_Type)
or else not Has_Anonymous_Access_Discriminant (R_Type)
or else not Comes_From_Source (Scope_Id)
+ or else Present (Wrapped_Statements (Scope_Id))
then
return;
end if;