[PATCH v2 3/3] gdb: use enumerate in gdbtypes.c

simon.marchi
2026-02-21T01:20:28Z

Use the new enumerate util to move to a range-based loop, while keeping
the counter.

Change-Id: If82eaec7afa4e78fa51e973fae4d0ecef728ea95
---
gdb/gdbtypes.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 2b6244d6f38b..73f65e72b167 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -44,6 +44,7 @@
#include "rust-lang.h"
#include "ada-lang.h"
#include "extract-store-integer.h"
+#include "gdbsupport/enumerate.h"

/* The value of an invalid conversion badness. */
#define INVALID_CONVERSION 100
@@ -4765,12 +4766,12 @@ rank_one_type (struct type *parm, struct type *arg, struct value *value)
static void
print_args (gdb::array_view<struct field> args, int spaces)
{
- for (int i = 0; i < args.size (); i++)
+ for (auto [i, arg] : gdb::ranges::views::enumerate (args))
{
gdb_printf
- ("%*s[%d] name '%s'\n", spaces, "", i,
- args[i].name () != NULL ? args[i].name () : "<NULL>");
- recursive_dump_type (args[i].type (), spaces + 2);
+ ("%*s[%zu] name '%s'\n", spaces, "", i,
+ arg.name () != nullptr ? arg.name () : "<NULL>");
+ recursive_dump_type (arg.type (), spaces + 2);
}
}

--
2.53.0