https://gcc.gnu.org/g:b56a782224d90205710311a3623769a5d8befe28
commit r16-1132-gb56a782224d90205710311a3623769a5d8befe28 Author: squirek <squi...@adacore.com> Date: Tue Jan 14 06:40:08 2025 +0000 ada: Spurious accessibility error with -gnatc The patch fixes an issue in the compiler whereby a spurious accessibility error gets generated in semantic checking mode (-gnatc) when an explicitly aliased formal gets used as an actual for an access disriminant in a return object. gcc/ada/ChangeLog: * accessibility.adb (Check_Return_Construct_Accessibility): Disable check generation when we are only checking semantics. Diff: --- gcc/ada/accessibility.adb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/gcc/ada/accessibility.adb b/gcc/ada/accessibility.adb index 8c85173aa34c..200f892a96f0 100644 --- a/gcc/ada/accessibility.adb +++ b/gcc/ada/accessibility.adb @@ -1642,6 +1642,13 @@ package body Accessibility is (No (Extra_Accessibility_Of_Result (Scope_Id)) and then Is_Formal_Of_Current_Function (Assoc_Expr) and then Is_Tagged_Type (Etype (Scope_Id))) + + -- Disable the check generation when we are only checking semantics + -- since required locals do not get generated (e.g. extra + -- accessibility of result), and constant folding can occur and + -- lead to spurious errors. + + and then Operating_Mode /= Check_Semantics then -- Generate a dynamic check based on the extra accessibility of -- the result or the scope of the current function.