Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [pushed] [gdb/build] Fix Wunused-variable in selftests::test_enumerate
@ 2026-04-18  9:54 Tom de Vries
  0 siblings, 0 replies; only message in thread
From: Tom de Vries @ 2026-04-18  9:54 UTC (permalink / raw)
  To: gdb-patches

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.
---
 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.  */

base-commit: f2e83582f4f1c6374afdd919fed59d713a225c0e
-- 
2.51.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-04-18  9:54 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-04-18  9:54 [pushed] [gdb/build] Fix Wunused-variable in selftests::test_enumerate Tom de Vries

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox