]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Spurious accessibility error with -gnatc
authorsquirek <squirek@adacore.com>
Tue, 14 Jan 2025 06:40:08 +0000 (06:40 +0000)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Thu, 5 Jun 2025 08:18:33 +0000 (10:18 +0200)
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.

gcc/ada/accessibility.adb

index 8c85173aa34cd0232bb462b47928b3670ce1faaf..200f892a96f097e850b532c9ca2ab1bb7fdb8c13 100644 (file)
@@ -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.