]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Suppress warning about unused variable in trivial quantification
authorPiotr Trojanek <trojanek@adacore.com>
Fri, 13 Mar 2026 11:54:06 +0000 (12:54 +0100)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Fri, 29 May 2026 08:49:48 +0000 (10:49 +0200)
When condition of a quantification expression is written as True or False, then
the user has likely done this on purpose and there is no need for a warning.

gcc/ada/ChangeLog:

* sem_ch4.adb (Analyze_Quantified_Expression): Suppress warning for
trivial conditions.

gcc/ada/sem_ch4.adb

index bd919e2bac7ffd3c01f24469967a2616ac41997b..7eeac98baf81b686fbe3c92636172e0739e91a1e 100644 (file)
@@ -4817,10 +4817,10 @@ package body Sem_Ch4 is
            and then not Is_Internal_Name (Chars (Loop_Id))
            and then not Has_Junk_Name (Loop_Id)
          then
-            if not Referenced (Loop_Id, Cond) then
-               Error_Msg_N ("?.t?unused variable &", Loop_Id);
-            else
+            if 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);
             end if;
          end if;
       end;