Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] Use gdb::Requires in gdb::ref_ptr
@ 2026-05-21 17:45 Tom Tromey
  2026-05-29 16:04 ` Andrew Burgess
  0 siblings, 1 reply; 2+ messages in thread
From: Tom Tromey @ 2026-05-21 17:45 UTC (permalink / raw)
  To: gdb-patches; +Cc: Andrew Burgess, Tom Tromey

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(-)

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Use gdb::Requires in gdb::ref_ptr
  2026-05-21 17:45 [PATCH] Use gdb::Requires in gdb::ref_ptr Tom Tromey
@ 2026-05-29 16:04 ` Andrew Burgess
  0 siblings, 0 replies; 2+ messages in thread
From: Andrew Burgess @ 2026-05-29 16:04 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches; +Cc: Tom Tromey

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-05-29 16:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-05-21 17:45 [PATCH] Use gdb::Requires in gdb::ref_ptr Tom Tromey
2026-05-29 16:04 ` Andrew Burgess

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox