]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Suppress warning for quantified expression with filters
authorPiotr Trojanek <trojanek@adacore.com>
Mon, 16 Mar 2026 12:40:44 +0000 (13:40 +0100)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Fri, 29 May 2026 08:49:48 +0000 (10:49 +0200)
If quantified expression has a filter, it becomes less clear whether we should
warn about quantified variable not being used.

gcc/ada/ChangeLog:

* sem_ch4.adb (Analyze_Quantified_Expression): If there is a filter,
then suppress the warning.

gcc/ada/sem_ch4.adb

index 7eeac98baf81b686fbe3c92636172e0739e91a1e..3a8edfb26df962372eeffff8fe5ce48b0faf0390 100644 (file)
@@ -4670,6 +4670,7 @@ package body Sem_Ch4 is
 
       Cond    : constant Node_Id := Condition (N);
       Loc     : constant Source_Ptr := Sloc (N);
+      Filter  : Node_Id;
       Loop_Id : Entity_Id;
       QE_Scop : Entity_Id;
 
@@ -4765,8 +4766,10 @@ package body Sem_Ch4 is
 
       if Present (Iterator_Specification (N)) then
          Loop_Id := Defining_Identifier (Iterator_Specification (N));
+         Filter  := Iterator_Filter (Iterator_Specification (N));
       else
          Loop_Id := Defining_Identifier (Loop_Parameter_Specification (N));
+         Filter  := Iterator_Filter (Loop_Parameter_Specification (N));
       end if;
 
       declare
@@ -4817,7 +4820,12 @@ package body Sem_Ch4 is
            and then not Is_Internal_Name (Chars (Loop_Id))
            and then not Has_Junk_Name (Loop_Id)
          then
-            if Referenced (Loop_Id, Cond) then
+            --  If there is a filter, then it is less clear whether the loop
+            --  variable is used or not; just ignore this case, for simplicity.
+
+            if Present (Filter) then
+               null;
+            elsif Referenced (Loop_Id, Cond) then
                Check_Subexpr (Cond, Kind => Full);
             elsif not Is_Trivial_Boolean (Cond) then
                Error_Msg_N ("?.t?unused variable &", Loop_Id);