Use gdb::Requires in gdb::ref_ptr

Message ID 20260521174527.2962256-1-tromey@adacore.com
State New
Headers
Series Use gdb::Requires in gdb::ref_ptr |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Test passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Test passed

Commit Message

Tom Tromey May 21, 2026, 5:45 p.m. UTC
  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.
---
 gdbsupport/gdb_ref_ptr.h | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)


base-commit: ea27a7ae9048367bde15246b248f856803efc674
  

Comments

Andrew Burgess May 29, 2026, 4:04 p.m. UTC | #1
Tom Tromey <tromey@adacore.com> writes:

> 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.

Thanks for putting this patch together.  LGTM.

Approved-By: Andrew Burgess <aburgess@redhat.com>

Thanks,
Andrew


> ---
>  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 @@ class ref_ptr
>  
>    /* 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 @@ class ref_ptr
>  
>    /* 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 @@ class ref_ptr
>  
>    /* 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 @@ class ref_ptr
>  
>    /* 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
>
> base-commit: ea27a7ae9048367bde15246b248f856803efc674
> -- 
> 2.54.0
  

Patch

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 @@  class ref_ptr
 
   /* 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 @@  class ref_ptr
 
   /* 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 @@  class ref_ptr
 
   /* 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 @@  class ref_ptr
 
   /* 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