]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdbsupport: remove variadicity from basic_safe_iterator constructors
authorSimon Marchi <simon.marchi@efficios.com>
Wed, 3 Sep 2025 14:50:03 +0000 (10:50 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Tue, 7 Oct 2025 20:22:15 +0000 (16:22 -0400)
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 <tom@tromey.com>
gdb/gdbthread.h
gdb/inferior.h
gdbsupport/safe-iterator.h

index 44f95c6fff4d333242d874b73292752a019bd6e7..26bd9f2b7e71e47fde0edc25b2454d67e79a5b40 100644 (file)
@@ -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);
index b02ec57b5de119e0c58d1ee2a216bdbb9a127f05..2e396ae11ce18e0476219896c408db3701af47f0 100644 (file)
@@ -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> 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
index 538816039345fd0ce640f2d93c3a83e96023f28e..4cb9a198037dfdc0049ad81f13869e6d59042506 100644 (file)
@@ -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<typename... Args>
-  explicit basic_safe_iterator (Args &&...args)
-    : m_it (std::forward<Args> (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<typename Arg>
-  explicit basic_safe_iterator (Arg &&arg, Arg &&arg2)
-    : m_it (std::forward<Arg> (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<Arg> (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 ()
   {}