]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Spurious reference warning on qualified expression
authorJustin Squirek <squirek@adacore.com>
Thu, 21 Dec 2023 18:31:27 +0000 (18:31 +0000)
committerMarc Poulhiès <poulhies@adacore.com>
Mon, 6 May 2024 09:11:29 +0000 (11:11 +0200)
This patch fixes an error in the compiler whereby an assignment to an out
formal (whose type requires a predicate check) can lead to spurious
"value may be referenced before it has a value" warnings when the RHS is a
qualified expression.

gcc/ada/

* sem_warn.adb (Within_Postcondition): Add case to ignore
references within generated predicate function calls.

gcc/ada/sem_warn.adb

index eaf9a257ba0417aba0c53b52705cff99e340faf0..0a54b3eda503027190712caa78cbc5d9d7edfcad 100644 (file)
@@ -1982,6 +1982,16 @@ package body Sem_Warn is
                            then
                               return True;
 
+                           --  Verify we are not within a generated predicate
+                           --  function call.
+
+                           elsif Nkind (Nod) = N_Function_Call
+                             and then Is_Entity_Name (Name (Nod))
+                             and then Is_Predicate_Function
+                                        (Entity (Name (Nod)))
+                           then
+                              return True;
+
                            elsif Present (Parent (Nod)) then
                               P := Parent (Nod);