[binutils-gdb] Use gdb::Requires in gdb::ref_ptr

Tom Tromey via Gdb-cvs <[email protected]> Fri, 29 May 2026 18:47:18 +0000 (GMT)
Newsgroups gmane.comp.gdb.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=742a479fc38a2b119d74a0bac270489911a1fd6c

commit 742a479fc38a2b119d74a0bac270489911a1fd6c
Author: Tom Tromey <[email protected]>
Date:   Thu May 21 11:41:53 2026 -0600

    Use gdb::Requires in gdb::ref_ptr
    
    Andrew pointed out that the use of is_convertible in gdb::ref_ptr is
    incorrect, and that it should instead check the value.  This can
    easily be done using gdb::Requires.
    
    Approved-By: Andrew Burgess <[email protected]>

Diff:
---
 gdbsupport/gdb_ref_ptr.h | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/gdbsupport/gdb_ref_ptr.h b/gdbsupport/gdb_ref_ptr.h
index 0eb654324c6..757c3f395ba 100644
--- a/gdbsupport/gdb_ref_ptr.h
+++ b/gdbsupport/gdb_ref_ptr.h
@@ -21,6 +21,7 @@
 #define GDBSUPPORT_GDB_REF_PTR_H
 
 #include <cstddef>
+#include "gdbsupport/traits.h"
 
 namespace gdb
 {
@@ -76,7 +77,7 @@ public:
 
   /* Copy another instance.  */
   template<typename U,
-	   typename = std::is_convertible<U *, T*>>
+	   typename = gdb::Requires<std::is_convertible<U *, T*>>>
   ref_ptr (const ref_ptr<U, Policy> &other)
     : m_obj (other.m_obj)
   {
@@ -93,7 +94,7 @@ public:
 
   /* Transfer ownership from OTHER.  */
   template<typename U,
-	   typename = std::is_convertible<U *, T*>>
+	   typename = gdb::Requires<std::is_convertible<U *, T*>>>
   ref_ptr (ref_ptr<U, Policy> &&other) noexcept
     : m_obj (other.m_obj)
   {
@@ -115,7 +116,7 @@ public:
 
   /* Copy another instance.  */
   template<typename U,
-	   typename = std::is_convertible<U *, T*>>
+	   typename = gdb::Requires<std::is_convertible<U *, T*>>>
   ref_ptr &operator= (const ref_ptr<U, Policy> &other)
   {
     /* Note that self-assignment is not checked here, as it isn't
@@ -141,7 +142,7 @@ public:
 
   /* Transfer ownership from OTHER.  */
   template<typename U,
-	   typename = std::is_convertible<U *, T*>>
+	   typename = gdb::Requires<std::is_convertible<U *, T*>>>
   ref_ptr &operator= (ref_ptr<U, Policy> &&other)
   {
     /* Note that self-assignment is not checked here, as it isn't