From ff20aab941bc9bb1e79011fd5dff94b16a203df0 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Wed, 3 Sep 2025 10:50:03 -0400 Subject: [PATCH] gdbsupport: remove variadicity from basic_safe_iterator constructors Change the constructors to accept `Iterator` objects directly. This requires the callers to explicitly pass `Iterator` object (unless perhaps `Iterator` has a non-explicit one-argument constructor. The rationale is the same as the previous patch: make the code easier to follow and make it easier to fix build errors, at the expense of making callers more explicit. Change-Id: Icd2a4ef971456ca250f96227a9b83c935d619451 Approved-By: Tom Tromey --- gdb/gdbthread.h | 5 +++-- gdb/inferior.h | 10 ++++++---- gdbsupport/safe-iterator.h | 28 +++++++++++----------------- 3 files changed, 20 insertions(+), 23 deletions(-) diff --git a/gdb/gdbthread.h b/gdb/gdbthread.h index 44f95c6fff4..26bd9f2b7e7 100644 --- a/gdb/gdbthread.h +++ b/gdb/gdbthread.h @@ -794,9 +794,10 @@ all_non_exited_threads (process_stratum_target *proc_target = nullptr, inline all_threads_safe_range all_threads_safe () { - all_threads_safe_iterator begin (all_threads_iterator::begin_t {}); + all_threads_iterator begin (all_threads_iterator::begin_t {}); + all_threads_safe_iterator safe_begin (std::move (begin)); - return all_threads_safe_range (std::move (begin)); + return all_threads_safe_range (std::move (safe_begin)); } extern int thread_count (process_stratum_target *proc_target); diff --git a/gdb/inferior.h b/gdb/inferior.h index b02ec57b5de..2e396ae11ce 100644 --- a/gdb/inferior.h +++ b/gdb/inferior.h @@ -502,9 +502,10 @@ public: */ inline safe_inf_threads_range threads_safe () { - safe_inf_threads_iterator begin (this->thread_list.begin ()); + inf_threads_iterator begin (this->thread_list.begin ()); + safe_inf_threads_iterator safe_begin (std::move (begin)); - return safe_inf_threads_range (std::move (begin)); + return safe_inf_threads_range (std::move (safe_begin)); } /* Find (non-exited) thread PTID of this inferior. */ @@ -832,9 +833,10 @@ extern intrusive_list inferior_list; inline all_inferiors_safe_range all_inferiors_safe () { - all_inferiors_safe_iterator begin (nullptr, inferior_list); + all_inferiors_iterator begin (nullptr, inferior_list); + all_inferiors_safe_iterator safe_begin (std::move (begin)); - return all_inferiors_safe_range (std::move (begin)); + return all_inferiors_safe_range (std::move (safe_begin)); } /* Returns a range representing all inferiors, suitable to use with diff --git a/gdbsupport/safe-iterator.h b/gdbsupport/safe-iterator.h index 53881603934..4cb9a198037 100644 --- a/gdbsupport/safe-iterator.h +++ b/gdbsupport/safe-iterator.h @@ -50,30 +50,24 @@ public: typedef typename Iterator::iterator_category iterator_category; typedef typename Iterator::difference_type difference_type; - /* Construct the begin iterator using the given arguments; the end iterator is - default constructed. */ - template - explicit basic_safe_iterator (Args &&...args) - : m_it (std::forward (args)...), - m_next (m_it) - { - if (m_it != m_end) - ++m_next; - } + /* Construct the iterator using the underlying iterator BEGIN; the end + iterator is default constructed. */ + explicit basic_safe_iterator (Iterator begin) + : basic_safe_iterator (std::move (begin), Iterator {}) + {} - /* Construct the iterator using the first argument, and construct - the end iterator using the second argument. */ - template - explicit basic_safe_iterator (Arg &&arg, Arg &&arg2) - : m_it (std::forward (arg)), + /* Construct the iterator using the underlying iterators BEGIN and END. */ + basic_safe_iterator (Iterator begin, Iterator end) + : m_it (std::move (begin)), m_next (m_it), - m_end (std::forward (arg2)) + m_end (std::move (end)) { if (m_it != m_end) ++m_next; } - /* Create a one-past-end iterator. */ + /* Create a one-past-end iterator. The underlying end iterator is obtained + by default-constructing. */ basic_safe_iterator () {} -- 2.47.3