From: simon.marchi@polymtl.ca
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@polymtl.ca>
Subject: [PATCH 2/2] gdb, gdbsupport: use [[nodiscard]] instead of ATTRIBUTE_UNUSED_RESULT
Date: Thu, 18 Jun 2026 13:51:00 -0400 [thread overview]
Message-ID: <20260618175118.3758778-2-simon.marchi@polymtl.ca> (raw)
In-Reply-To: <20260618175118.3758778-1-simon.marchi@polymtl.ca>
From: Simon Marchi <simon.marchi@polymtl.ca>
Since we require C++17, replace the uses of the ATTRIBUTE_UNUSED_RESULT macro
(which expands to __attribute__ ((__warn_unused_result__))) with the
standard [[nodiscard]] attribute, and drop the macro definition from
gdbsupport/common-defs.h.
Change-Id: I6aa0386ce709e8cce81d2a705362bdd4ceccb543
---
gdb/parser-defs.h | 2 +-
gdb/remote.c | 2 +-
gdb/stap-probe.c | 12 +++++-------
gdbsupport/buildargv.h | 2 +-
gdbsupport/common-defs.h | 1 -
gdbsupport/gdb_ref_ptr.h | 2 +-
gdbsupport/scoped_fd.h | 2 +-
gdbsupport/scoped_mmap.h | 2 +-
8 files changed, 11 insertions(+), 14 deletions(-)
diff --git a/gdb/parser-defs.h b/gdb/parser-defs.h
index cfa9d9c111da..96355eb3ca4b 100644
--- a/gdb/parser-defs.h
+++ b/gdb/parser-defs.h
@@ -49,7 +49,7 @@ struct expr_builder
/* Resize the allocated expression to the correct size, and return
it as an expression_up -- passing ownership to the caller. */
- ATTRIBUTE_UNUSED_RESULT expression_up release ()
+ [[nodiscard]] expression_up release ()
{
return std::move (expout);
}
diff --git a/gdb/remote.c b/gdb/remote.c
index 43df087b83b3..e6dc3a56e28d 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -13934,7 +13934,7 @@ class scoped_remote_fd
DISABLE_COPY_AND_ASSIGN (scoped_remote_fd);
/* Release ownership of the file descriptor, and return it. */
- ATTRIBUTE_UNUSED_RESULT int release () noexcept
+ [[nodiscard]] int release () noexcept
{
int fd = m_fd;
m_fd = -1;
diff --git a/gdb/stap-probe.c b/gdb/stap-probe.c
index d28cee8168c3..62fc18f7a958 100644
--- a/gdb/stap-probe.c
+++ b/gdb/stap-probe.c
@@ -261,13 +261,11 @@ enum stap_operand_prec
STAP_OPERAND_PREC_MUL
};
-static expr::operation_up stap_parse_argument_1 (struct stap_parse_info *p,
- expr::operation_up &&lhs,
- enum stap_operand_prec prec)
- ATTRIBUTE_UNUSED_RESULT;
+[[nodiscard]] static expr::operation_up stap_parse_argument_1
+ (stap_parse_info *p, expr::operation_up &&lhs, stap_operand_prec prec);
-static expr::operation_up stap_parse_argument_conditionally
- (struct stap_parse_info *p) ATTRIBUTE_UNUSED_RESULT;
+[[nodiscard]] static expr::operation_up stap_parse_argument_conditionally
+ (stap_parse_info *p);
/* Returns true if *S is an operator, false otherwise. */
@@ -1072,7 +1070,7 @@ stap_parse_argument_conditionally (struct stap_parse_info *p)
/* Helper function for `stap_parse_argument'. Please, see its comments to
better understand what this function does. */
-static expr::operation_up ATTRIBUTE_UNUSED_RESULT
+[[nodiscard]] static expr::operation_up
stap_parse_argument_1 (struct stap_parse_info *p,
expr::operation_up &&lhs_in,
enum stap_operand_prec prec)
diff --git a/gdbsupport/buildargv.h b/gdbsupport/buildargv.h
index 788c1e38730b..6475ee174de5 100644
--- a/gdbsupport/buildargv.h
+++ b/gdbsupport/buildargv.h
@@ -102,7 +102,7 @@ class gdb_argv
/* Return the underlying array, transferring ownership to the
caller. */
- ATTRIBUTE_UNUSED_RESULT char **release ()
+ [[nodiscard]] char **release ()
{
char **result = m_argv;
m_argv = NULL;
diff --git a/gdbsupport/common-defs.h b/gdbsupport/common-defs.h
index 1c0ae0ad9d1b..ca08939676d9 100644
--- a/gdbsupport/common-defs.h
+++ b/gdbsupport/common-defs.h
@@ -202,7 +202,6 @@
#undef ATTRIBUTE_NONNULL
#define ATTRIBUTE_NONNULL(m)
-#define ATTRIBUTE_UNUSED_RESULT __attribute__ ((__warn_unused_result__))
#define ATTRIBUTE_USED __attribute__ ((__used__))
#include "libiberty.h"
diff --git a/gdbsupport/gdb_ref_ptr.h b/gdbsupport/gdb_ref_ptr.h
index 757c3f395bab..77aebd82e5d7 100644
--- a/gdbsupport/gdb_ref_ptr.h
+++ b/gdbsupport/gdb_ref_ptr.h
@@ -183,7 +183,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 () noexcept
+ [[nodiscard]] T *release () noexcept
{
T *result = m_obj;
diff --git a/gdbsupport/scoped_fd.h b/gdbsupport/scoped_fd.h
index 08102eda8ce3..03255ea8db7a 100644
--- a/gdbsupport/scoped_fd.h
+++ b/gdbsupport/scoped_fd.h
@@ -56,7 +56,7 @@ class scoped_fd
DISABLE_COPY_AND_ASSIGN (scoped_fd);
- ATTRIBUTE_UNUSED_RESULT int release () noexcept
+ [[nodiscard]] int release () noexcept
{
int fd = m_fd;
m_fd = -1;
diff --git a/gdbsupport/scoped_mmap.h b/gdbsupport/scoped_mmap.h
index 84ad2c38a152..902a1631b2f8 100644
--- a/gdbsupport/scoped_mmap.h
+++ b/gdbsupport/scoped_mmap.h
@@ -52,7 +52,7 @@ class scoped_mmap
DISABLE_COPY_AND_ASSIGN (scoped_mmap);
- ATTRIBUTE_UNUSED_RESULT void *release () noexcept
+ [[nodiscard]] void *release () noexcept
{
void *mem = m_mem;
m_mem = MAP_FAILED;
--
2.54.0
next prev parent reply other threads:[~2026-06-18 17:52 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-18 17:50 [PATCH 1/2] gdb, gdbserver, gdbsupport: use [[maybe_unused]] instead of ATTRIBUTE_UNUSED simon.marchi
2026-06-18 17:51 ` simon.marchi [this message]
2026-06-19 12:49 ` Tom de Vries
2026-06-26 15:20 ` Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260618175118.3758778-2-simon.marchi@polymtl.ca \
--to=simon.marchi@polymtl.ca \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox