]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: add noexcept to relevant methods of class ref_ptr
authorMatthieu Longo <matthieu.longo@arm.com>
Thu, 23 Oct 2025 16:20:50 +0000 (17:20 +0100)
committerMatthieu Longo <matthieu.longo@arm.com>
Mon, 26 Jan 2026 14:29:00 +0000 (14:29 +0000)
This patch aims at improving code readability and maintainability
by adding the 'noexcept' attribute to some constructors and
methods of class 'ref_ptr' to make clear that no exception is
supposed to be raised from them.
As an additional benefit, the compiler doesn't need to generate
the stack unwinding code for those constructors and methods.

Approved-By: Tom Tromey <tom@tromey.com>
gdbsupport/gdb_ref_ptr.h

index b6d5346373f87aeb689a3d9c7225c8e702103a1d..3d01bf4441b1b157bfbf7160d65cbc1c300c0a9f 100644 (file)
@@ -51,20 +51,20 @@ class ref_ptr
  public:
 
   /* Create a new NULL instance.  */
-  ref_ptr ()
+  ref_ptr () noexcept
     : m_obj (NULL)
   {
   }
 
   /* Create a new NULL instance.  Note that this is not explicit.  */
-  ref_ptr (const std::nullptr_t)
+  ref_ptr (const std::nullptr_t) noexcept
     : m_obj (NULL)
   {
   }
 
   /* Create a new instance.  OBJ is a reference, management of which
      is now transferred to this class.  */
-  explicit ref_ptr (T *obj)
+  explicit ref_ptr (T *obj) noexcept
     : m_obj (obj)
   {
   }
@@ -127,7 +127,7 @@ class ref_ptr
 
   /* Return this instance's referent without changing the state of
      this class.  */
-  T *get () const
+  T *get () const noexcept
   {
     return m_obj;
   }
@@ -135,7 +135,7 @@ class ref_ptr
   /* Return this instance's referent, and stop managing this
      reference.  The caller is now responsible for the ownership of
      the reference.  */
-  ATTRIBUTE_UNUSED_RESULT T *release ()
+  ATTRIBUTE_UNUSED_RESULT T *release () noexcept
   {
     T *result = m_obj;
 
@@ -144,7 +144,7 @@ class ref_ptr
   }
 
   /* Let users refer to members of the underlying pointer.  */
-  T *operator-> () const
+  T *operator-> () const noexcept
   {
     return m_obj;
   }