From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [pushed] [gdb/build] Fix Wunused-variable in selftests::test_enumerate
Date: Sat, 18 Apr 2026 11:54:23 +0200 [thread overview]
Message-ID: <20260418095423.2877658-1-tdevries@suse.de> (raw)
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
reply other threads:[~2026-04-18 9:54 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260418095423.2877658-1-tdevries@suse.de \
--to=tdevries@suse.de \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox