From: Matthieu Longo Date: Thu, 23 Oct 2025 16:20:50 +0000 (+0100) Subject: gdb: add noexcept to relevant methods of class ref_ptr X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9fbbc2ed43ef26834ca46aededff3c569c2431c6;p=thirdparty%2Fbinutils-gdb.git gdb: add noexcept to relevant methods of class ref_ptr 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 --- diff --git a/gdbsupport/gdb_ref_ptr.h b/gdbsupport/gdb_ref_ptr.h index b6d5346373f..3d01bf4441b 100644 --- a/gdbsupport/gdb_ref_ptr.h +++ b/gdbsupport/gdb_ref_ptr.h @@ -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; }