[binutils-gdb] [gdb/build] Fix Wunused-variable in selftests::test_enumerate

Tom de Vries via Gdb-cvs <[email protected]>
Newsgroups gmane.comp.gdb.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=cb345f65ba05b6e1de221adaf1b032efad8aed08

commit cb345f65ba05b6e1de221adaf1b032efad8aed08
Author: Tom de Vries <[email protected]>
Date:   Sat Apr 18 11:54:01 2026 +0200

    [gdb/build] Fix Wunused-variable in selftests::test_enumerate
    
    On openSUSE Leap 15.6, with gcc 7.5.0, I ran into:
    ...
    enumerate-selftests.c: In function 'void selftests::test_enumerate()':
    enumerate-selftests.c:85:22: error: \
      unused variable 'i' [-Werror=unused-variable]
         for (auto [i, val] : gdb::ranges::views::enumerate (vec))
                          ^
    cc1plus: all warnings being treated as errors
    ...
    
    Fix this by checking the value of i.
    
    Tested on x86_64-linux.

Diff:
---
 gdb/unittests/enumerate-selftests.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/gdb/unittests/enumerate-selftests.c b/gdb/unittests/enumerate-selftests.c
index ddda29f6625..4ca85277fec 100644
--- a/gdb/unittests/enumerate-selftests.c
+++ b/gdb/unittests/enumerate-selftests.c
@@ -81,11 +81,17 @@ test_enumerate ()
   {
     std::vector<int> vec = { 1, 2, 3 };
     std::vector<int> expected = { 10, 20, 30 };
+    std::vector<int> actual_i;
+    std::vector<int> expected_i = { 0, 1, 2 };
 
     for (auto [i, val] : gdb::ranges::views::enumerate (vec))
-      val *= 10;
+      {
+	val *= 10;
+	actual_i.push_back (i);
+      }
 
     SELF_CHECK (vec == expected);
+    SELF_CHECK (actual_i == expected_i);
   }
 
   /* Test enumeration over an empty container.  */
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.