* [PATCH 1/2] gdb, gdbserver, gdbsupport: use [[maybe_unused]] instead of ATTRIBUTE_UNUSED
@ 2026-06-18 17:50 simon.marchi
2026-06-18 17:51 ` [PATCH 2/2] gdb, gdbsupport: use [[nodiscard]] instead of ATTRIBUTE_UNUSED_RESULT simon.marchi
2026-06-19 12:49 ` [PATCH 1/2] gdb, gdbserver, gdbsupport: use [[maybe_unused]] instead of ATTRIBUTE_UNUSED Tom de Vries
0 siblings, 2 replies; 4+ messages in thread
From: simon.marchi @ 2026-06-18 17:50 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi
From: Simon Marchi <simon.marchi@polymtl.ca>
Since we require C++17, replace the uses of the ATTRIBUTE_UNUSED macro
(which expands to __attribute__ ((__unused__))) with the standard
[[maybe_unused]] attribute.
I think that some of these attribute uses are not necessary, but I did
not make an attempt to remove them, that would be for another patch.
Change-Id: I62529d94153c65e2b3c49ff5330292e60c8a0f9e
---
gdb/inferior.c | 4 ++--
gdb/inflow.c | 2 +-
gdb/linux-fork.c | 2 +-
gdb/mi/mi-interp.c | 2 +-
gdb/python/py-utils.c | 2 +-
gdb/remote.c | 2 +-
gdb/source-cache.c | 6 +++---
gdb/thread.c | 4 ++--
gdb/typeprint.c | 4 ++--
gdb/unittests/enum-flags-selftests.c | 4 ++--
gdb/valprint.c | 4 ++--
gdbserver/linux-aarch64-low.cc | 6 +++---
gdbserver/x86-tdesc.h | 4 ++--
gdbsupport/safe-strerror.cc | 4 ++--
gdbsupport/thread-pool.cc | 6 +++---
15 files changed, 28 insertions(+), 28 deletions(-)
diff --git a/gdb/inferior.c b/gdb/inferior.c
index 1481f46cdd18..7d54845f28ac 100644
--- a/gdb/inferior.c
+++ b/gdb/inferior.c
@@ -432,7 +432,7 @@ find_inferior_for_program_space (struct program_space *pspace)
int
have_inferiors (void)
{
- for (inferior *inf ATTRIBUTE_UNUSED : all_non_exited_inferiors ())
+ for ([[maybe_unused]] inferior *inf : all_non_exited_inferiors ())
return 1;
return 0;
@@ -449,7 +449,7 @@ number_of_live_inferiors (process_stratum_target *proc_target)
for (inferior *inf : all_non_exited_inferiors (proc_target))
if (inf->has_execution ())
- for (thread_info &tp ATTRIBUTE_UNUSED : inf->non_exited_threads ())
+ for ([[maybe_unused]] thread_info &tp : inf->non_exited_threads ())
{
/* Found a live thread in this inferior, go to the next
inferior. */
diff --git a/gdb/inflow.c b/gdb/inflow.c
index c40ad2cf5294..e3a080dbd657 100644
--- a/gdb/inflow.c
+++ b/gdb/inflow.c
@@ -493,7 +493,7 @@ child_terminal_ours_1 (target_terminal_state desired_state)
if (gdb_tty_state != desired_state)
{
- int result ATTRIBUTE_UNUSED;
+ [[maybe_unused]] int result;
/* Ignore SIGTTOU since it will happen when we try to set the
terminal's pgrp. */
diff --git a/gdb/linux-fork.c b/gdb/linux-fork.c
index 92afa4dde6db..fac35e13afb8 100644
--- a/gdb/linux-fork.c
+++ b/gdb/linux-fork.c
@@ -963,7 +963,7 @@ inf_has_multiple_threads ()
/* Return true as soon as we see the second thread of the current
inferior. */
- for (thread_info &tp ATTRIBUTE_UNUSED : current_inferior ()->threads ())
+ for ([[maybe_unused]] thread_info &tp : current_inferior ()->threads ())
if (++count > 1)
return true;
diff --git a/gdb/mi/mi-interp.c b/gdb/mi/mi-interp.c
index 1a0d34106ed1..998409563e97 100644
--- a/gdb/mi/mi-interp.c
+++ b/gdb/mi/mi-interp.c
@@ -637,7 +637,7 @@ static bool
multiple_inferiors_p ()
{
int count = 0;
- for (inferior *inf ATTRIBUTE_UNUSED : all_non_exited_inferiors ())
+ for ([[maybe_unused]] inferior *inf : all_non_exited_inferiors ())
{
count++;
if (count > 1)
diff --git a/gdb/python/py-utils.c b/gdb/python/py-utils.c
index a831b96eb387..3979343acde9 100644
--- a/gdb/python/py-utils.c
+++ b/gdb/python/py-utils.c
@@ -314,7 +314,7 @@ gdb_py_int_as_long (PyObject *obj, long *result)
PyObject *
gdb_py_generic_dict_getter (PyObject *self,
- void *closure ATTRIBUTE_UNUSED)
+ [[maybe_unused]] void *closure)
{
PyObject **py_dict_ptr = gdbpy_dict_wrapper::compute_addr (self);
PyObject *py_dict = *py_dict_ptr;
diff --git a/gdb/remote.c b/gdb/remote.c
index f8c7383cb037..43df087b83b3 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -4546,7 +4546,7 @@ static bool
has_single_non_exited_thread (inferior *inf)
{
int count = 0;
- for (thread_info &tp ATTRIBUTE_UNUSED : inf->non_exited_threads ())
+ for ([[maybe_unused]] thread_info &tp : inf->non_exited_threads ())
if (++count > 1)
break;
return count == 1;
diff --git a/gdb/source-cache.c b/gdb/source-cache.c
index 6e8acab35044..0a64745ee585 100644
--- a/gdb/source-cache.c
+++ b/gdb/source-cache.c
@@ -199,9 +199,9 @@ get_language_name (enum language lang)
succeeded. */
static bool
-try_source_highlight (std::string &contents ATTRIBUTE_UNUSED,
- enum language lang ATTRIBUTE_UNUSED,
- const std::string &fullname ATTRIBUTE_UNUSED)
+try_source_highlight ([[maybe_unused]] std::string &contents,
+ [[maybe_unused]] enum language lang,
+ [[maybe_unused]] const std::string &fullname)
{
#ifdef HAVE_SOURCE_HIGHLIGHT
if (!use_gnu_source_highlight)
diff --git a/gdb/thread.c b/gdb/thread.c
index 96c733e0629b..ffb980546b93 100644
--- a/gdb/thread.c
+++ b/gdb/thread.c
@@ -476,7 +476,7 @@ thread_step_over_chain_length (const thread_step_over_list &l)
{
int num = 0;
- for (const thread_info &thread ATTRIBUTE_UNUSED : l)
+ for ([[maybe_unused]] const thread_info &thread : l)
++num;
return num;
@@ -626,7 +626,7 @@ find_thread (find_thread_callback_ftype callback)
bool
any_thread_p ()
{
- for (thread_info &tp ATTRIBUTE_UNUSED : all_threads ())
+ for ([[maybe_unused]] thread_info &tp : all_threads ())
return true;
return false;
}
diff --git a/gdb/typeprint.c b/gdb/typeprint.c
index 31a9c1814a31..01c6c218a5d5 100644
--- a/gdb/typeprint.c
+++ b/gdb/typeprint.c
@@ -516,11 +516,11 @@ ptype_command (const char *type_name, int from_tty)
}
/* Meant to be used in debug sessions, so don't export it in a header file. */
-extern void ATTRIBUTE_UNUSED debug_type (struct type *type);
+[[maybe_unused]] extern void debug_type (struct type *type);
/* Print TYPE. */
-void ATTRIBUTE_UNUSED
+[[maybe_unused]] void
debug_type (struct type *type)
{
type_print (type, "", gdb_stdlog, 1);
diff --git a/gdb/unittests/enum-flags-selftests.c b/gdb/unittests/enum-flags-selftests.c
index bf748e873035..ca404bfa3ebe 100644
--- a/gdb/unittests/enum-flags-selftests.c
+++ b/gdb/unittests/enum-flags-selftests.c
@@ -70,8 +70,8 @@ static_assert (std::is_trivially_copyable<EnumFlag>::value);
below. Their names (and types) match the uppercase type names
exposed by CHECK_VALID just to make the expressions easier to
follow. */
-static RawEnum re ATTRIBUTE_UNUSED;
-static EnumFlag ef ATTRIBUTE_UNUSED;
+[[maybe_unused]] static RawEnum re;
+[[maybe_unused]] static EnumFlag ef;
/* First, compile-time tests that:
diff --git a/gdb/valprint.c b/gdb/valprint.c
index 50a4663ca3b5..67bfbf589301 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -1232,11 +1232,11 @@ value_print (struct value *val, struct ui_file *stream,
}
/* Meant to be used in debug sessions, so don't export it in a header file. */
-extern void ATTRIBUTE_UNUSED debug_val (struct value *val);
+[[maybe_unused]] extern void debug_val (struct value *val);
/* Print VAL. */
-void ATTRIBUTE_UNUSED
+[[maybe_unused]] void
debug_val (struct value *val)
{
value_print (val, gdb_stdlog, &user_print_options);
diff --git a/gdbserver/linux-aarch64-low.cc b/gdbserver/linux-aarch64-low.cc
index a2588a6e2a9c..b68d39e1b803 100644
--- a/gdbserver/linux-aarch64-low.cc
+++ b/gdbserver/linux-aarch64-low.cc
@@ -741,7 +741,7 @@ aarch64_target::low_new_fork (process_info *parent,
static void
aarch64_sve_regs_copy_to_regcache (struct regcache *regcache,
- ATTRIBUTE_UNUSED const void *buf)
+ [[maybe_unused]] const void *buf)
{
/* BUF is unused here since we collect the data straight from a ptrace
request in aarch64_sve_regs_copy_to_reg_buf, therefore bypassing
@@ -776,7 +776,7 @@ aarch64_sve_regs_copy_from_regcache (struct regcache *regcache, void *buf)
static void
aarch64_za_regs_copy_to_regcache (struct regcache *regcache,
- ATTRIBUTE_UNUSED const void *buf)
+ [[maybe_unused]] const void *buf)
{
/* BUF is unused here since we collect the data straight from a ptrace
request, therefore bypassing gdbserver's own call to ptrace. */
@@ -822,7 +822,7 @@ aarch64_za_regs_copy_from_regcache (struct regcache *regcache, void *buf)
static void
aarch64_zt_regs_copy_to_regcache (struct regcache *regcache,
- ATTRIBUTE_UNUSED const void *buf)
+ [[maybe_unused]] const void *buf)
{
/* BUF is unused here since we collect the data straight from a ptrace
request, therefore bypassing gdbserver's own call to ptrace. */
diff --git a/gdbserver/x86-tdesc.h b/gdbserver/x86-tdesc.h
index 4ed6d6635bbb..ce0c6c1be90d 100644
--- a/gdbserver/x86-tdesc.h
+++ b/gdbserver/x86-tdesc.h
@@ -20,8 +20,8 @@
/* The "expedite" registers for x86 targets. Since whether the
variable is used depends on host/configuration, we mark it
- ATTRIBUTE_UNUSED to keep it simple here. */
-static const char *i386_expedite_regs[] ATTRIBUTE_UNUSED
+ [[maybe_unused]] to keep it simple here. */
+[[maybe_unused]] static const char *i386_expedite_regs[]
= {"ebp", "esp", "eip", NULL};
#ifdef __x86_64__
diff --git a/gdbsupport/safe-strerror.cc b/gdbsupport/safe-strerror.cc
index d53cf84511fd..ad25cfc3d765 100644
--- a/gdbsupport/safe-strerror.cc
+++ b/gdbsupport/safe-strerror.cc
@@ -26,14 +26,14 @@
function. */
/* Called if we have a XSI-compliant strerror_r. */
-ATTRIBUTE_UNUSED static char *
+[[maybe_unused]] static char *
select_strerror_r (int res, char *buf)
{
return res == 0 ? buf : nullptr;
}
/* Called if we have a GNU strerror_r. */
-ATTRIBUTE_UNUSED static char *
+[[maybe_unused]] static char *
select_strerror_r (char *res, char *)
{
return res;
diff --git a/gdbsupport/thread-pool.cc b/gdbsupport/thread-pool.cc
index 4dc72e566428..12329ea98831 100644
--- a/gdbsupport/thread-pool.cc
+++ b/gdbsupport/thread-pool.cc
@@ -44,14 +44,14 @@
takes a printf-style format and an argument. This wrapper handles the
difference. */
-ATTRIBUTE_UNUSED static void
+[[maybe_unused]] static void
do_set_thread_name (int (*set_name) (pthread_t, const char *, void *),
const char *name)
{
set_name (pthread_self (), "%s", const_cast<char *> (name));
}
-ATTRIBUTE_UNUSED static void
+[[maybe_unused]] static void
do_set_thread_name (int (*set_name) (pthread_t, const char *),
const char *name)
{
@@ -60,7 +60,7 @@ do_set_thread_name (int (*set_name) (pthread_t, const char *),
/* The macOS man page says that pthread_setname_np returns "void", but
the headers actually declare it returning "int". */
-ATTRIBUTE_UNUSED static void
+[[maybe_unused]] static void
do_set_thread_name (int (*set_name) (const char *), const char *name)
{
set_name (name);
base-commit: cdfda31c0d6b85cfff7fddeabffa570176161548
--
2.54.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 2/2] gdb, gdbsupport: use [[nodiscard]] instead of ATTRIBUTE_UNUSED_RESULT
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
2026-06-19 12:49 ` [PATCH 1/2] gdb, gdbserver, gdbsupport: use [[maybe_unused]] instead of ATTRIBUTE_UNUSED Tom de Vries
1 sibling, 0 replies; 4+ messages in thread
From: simon.marchi @ 2026-06-18 17:51 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] gdb, gdbserver, gdbsupport: use [[maybe_unused]] instead of ATTRIBUTE_UNUSED
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 ` [PATCH 2/2] gdb, gdbsupport: use [[nodiscard]] instead of ATTRIBUTE_UNUSED_RESULT simon.marchi
@ 2026-06-19 12:49 ` Tom de Vries
2026-06-26 15:20 ` Tom Tromey
1 sibling, 1 reply; 4+ messages in thread
From: Tom de Vries @ 2026-06-19 12:49 UTC (permalink / raw)
To: simon.marchi, gdb-patches
On 6/18/26 7:50 PM, simon.marchi@polymtl.ca wrote:
> From: Simon Marchi <simon.marchi@polymtl.ca>
>
> Since we require C++17, replace the uses of the ATTRIBUTE_UNUSED macro
> (which expands to __attribute__ ((__unused__))) with the standard
> [[maybe_unused]] attribute.
>
> I think that some of these attribute uses are not necessary, but I did
> not make an attempt to remove them, that would be for another patch.
>
Hi,
these both look fine to me.
Reviewed-By: Tom de Vries <tdevries@suse.de>
Thanks,
- Tom
> Change-Id: I62529d94153c65e2b3c49ff5330292e60c8a0f9e
> ---
> gdb/inferior.c | 4 ++--
> gdb/inflow.c | 2 +-
> gdb/linux-fork.c | 2 +-
> gdb/mi/mi-interp.c | 2 +-
> gdb/python/py-utils.c | 2 +-
> gdb/remote.c | 2 +-
> gdb/source-cache.c | 6 +++---
> gdb/thread.c | 4 ++--
> gdb/typeprint.c | 4 ++--
> gdb/unittests/enum-flags-selftests.c | 4 ++--
> gdb/valprint.c | 4 ++--
> gdbserver/linux-aarch64-low.cc | 6 +++---
> gdbserver/x86-tdesc.h | 4 ++--
> gdbsupport/safe-strerror.cc | 4 ++--
> gdbsupport/thread-pool.cc | 6 +++---
> 15 files changed, 28 insertions(+), 28 deletions(-)
>
> diff --git a/gdb/inferior.c b/gdb/inferior.c
> index 1481f46cdd18..7d54845f28ac 100644
> --- a/gdb/inferior.c
> +++ b/gdb/inferior.c
> @@ -432,7 +432,7 @@ find_inferior_for_program_space (struct program_space *pspace)
> int
> have_inferiors (void)
> {
> - for (inferior *inf ATTRIBUTE_UNUSED : all_non_exited_inferiors ())
> + for ([[maybe_unused]] inferior *inf : all_non_exited_inferiors ())
> return 1;
>
> return 0;
> @@ -449,7 +449,7 @@ number_of_live_inferiors (process_stratum_target *proc_target)
>
> for (inferior *inf : all_non_exited_inferiors (proc_target))
> if (inf->has_execution ())
> - for (thread_info &tp ATTRIBUTE_UNUSED : inf->non_exited_threads ())
> + for ([[maybe_unused]] thread_info &tp : inf->non_exited_threads ())
> {
> /* Found a live thread in this inferior, go to the next
> inferior. */
> diff --git a/gdb/inflow.c b/gdb/inflow.c
> index c40ad2cf5294..e3a080dbd657 100644
> --- a/gdb/inflow.c
> +++ b/gdb/inflow.c
> @@ -493,7 +493,7 @@ child_terminal_ours_1 (target_terminal_state desired_state)
>
> if (gdb_tty_state != desired_state)
> {
> - int result ATTRIBUTE_UNUSED;
> + [[maybe_unused]] int result;
>
> /* Ignore SIGTTOU since it will happen when we try to set the
> terminal's pgrp. */
> diff --git a/gdb/linux-fork.c b/gdb/linux-fork.c
> index 92afa4dde6db..fac35e13afb8 100644
> --- a/gdb/linux-fork.c
> +++ b/gdb/linux-fork.c
> @@ -963,7 +963,7 @@ inf_has_multiple_threads ()
>
> /* Return true as soon as we see the second thread of the current
> inferior. */
> - for (thread_info &tp ATTRIBUTE_UNUSED : current_inferior ()->threads ())
> + for ([[maybe_unused]] thread_info &tp : current_inferior ()->threads ())
> if (++count > 1)
> return true;
>
> diff --git a/gdb/mi/mi-interp.c b/gdb/mi/mi-interp.c
> index 1a0d34106ed1..998409563e97 100644
> --- a/gdb/mi/mi-interp.c
> +++ b/gdb/mi/mi-interp.c
> @@ -637,7 +637,7 @@ static bool
> multiple_inferiors_p ()
> {
> int count = 0;
> - for (inferior *inf ATTRIBUTE_UNUSED : all_non_exited_inferiors ())
> + for ([[maybe_unused]] inferior *inf : all_non_exited_inferiors ())
> {
> count++;
> if (count > 1)
> diff --git a/gdb/python/py-utils.c b/gdb/python/py-utils.c
> index a831b96eb387..3979343acde9 100644
> --- a/gdb/python/py-utils.c
> +++ b/gdb/python/py-utils.c
> @@ -314,7 +314,7 @@ gdb_py_int_as_long (PyObject *obj, long *result)
>
> PyObject *
> gdb_py_generic_dict_getter (PyObject *self,
> - void *closure ATTRIBUTE_UNUSED)
> + [[maybe_unused]] void *closure)
> {
> PyObject **py_dict_ptr = gdbpy_dict_wrapper::compute_addr (self);
> PyObject *py_dict = *py_dict_ptr;
> diff --git a/gdb/remote.c b/gdb/remote.c
> index f8c7383cb037..43df087b83b3 100644
> --- a/gdb/remote.c
> +++ b/gdb/remote.c
> @@ -4546,7 +4546,7 @@ static bool
> has_single_non_exited_thread (inferior *inf)
> {
> int count = 0;
> - for (thread_info &tp ATTRIBUTE_UNUSED : inf->non_exited_threads ())
> + for ([[maybe_unused]] thread_info &tp : inf->non_exited_threads ())
> if (++count > 1)
> break;
> return count == 1;
> diff --git a/gdb/source-cache.c b/gdb/source-cache.c
> index 6e8acab35044..0a64745ee585 100644
> --- a/gdb/source-cache.c
> +++ b/gdb/source-cache.c
> @@ -199,9 +199,9 @@ get_language_name (enum language lang)
> succeeded. */
>
> static bool
> -try_source_highlight (std::string &contents ATTRIBUTE_UNUSED,
> - enum language lang ATTRIBUTE_UNUSED,
> - const std::string &fullname ATTRIBUTE_UNUSED)
> +try_source_highlight ([[maybe_unused]] std::string &contents,
> + [[maybe_unused]] enum language lang,
> + [[maybe_unused]] const std::string &fullname)
> {
> #ifdef HAVE_SOURCE_HIGHLIGHT
> if (!use_gnu_source_highlight)
> diff --git a/gdb/thread.c b/gdb/thread.c
> index 96c733e0629b..ffb980546b93 100644
> --- a/gdb/thread.c
> +++ b/gdb/thread.c
> @@ -476,7 +476,7 @@ thread_step_over_chain_length (const thread_step_over_list &l)
> {
> int num = 0;
>
> - for (const thread_info &thread ATTRIBUTE_UNUSED : l)
> + for ([[maybe_unused]] const thread_info &thread : l)
> ++num;
>
> return num;
> @@ -626,7 +626,7 @@ find_thread (find_thread_callback_ftype callback)
> bool
> any_thread_p ()
> {
> - for (thread_info &tp ATTRIBUTE_UNUSED : all_threads ())
> + for ([[maybe_unused]] thread_info &tp : all_threads ())
> return true;
> return false;
> }
> diff --git a/gdb/typeprint.c b/gdb/typeprint.c
> index 31a9c1814a31..01c6c218a5d5 100644
> --- a/gdb/typeprint.c
> +++ b/gdb/typeprint.c
> @@ -516,11 +516,11 @@ ptype_command (const char *type_name, int from_tty)
> }
>
> /* Meant to be used in debug sessions, so don't export it in a header file. */
> -extern void ATTRIBUTE_UNUSED debug_type (struct type *type);
> +[[maybe_unused]] extern void debug_type (struct type *type);
>
> /* Print TYPE. */
>
> -void ATTRIBUTE_UNUSED
> +[[maybe_unused]] void
> debug_type (struct type *type)
> {
> type_print (type, "", gdb_stdlog, 1);
> diff --git a/gdb/unittests/enum-flags-selftests.c b/gdb/unittests/enum-flags-selftests.c
> index bf748e873035..ca404bfa3ebe 100644
> --- a/gdb/unittests/enum-flags-selftests.c
> +++ b/gdb/unittests/enum-flags-selftests.c
> @@ -70,8 +70,8 @@ static_assert (std::is_trivially_copyable<EnumFlag>::value);
> below. Their names (and types) match the uppercase type names
> exposed by CHECK_VALID just to make the expressions easier to
> follow. */
> -static RawEnum re ATTRIBUTE_UNUSED;
> -static EnumFlag ef ATTRIBUTE_UNUSED;
> +[[maybe_unused]] static RawEnum re;
> +[[maybe_unused]] static EnumFlag ef;
>
> /* First, compile-time tests that:
>
> diff --git a/gdb/valprint.c b/gdb/valprint.c
> index 50a4663ca3b5..67bfbf589301 100644
> --- a/gdb/valprint.c
> +++ b/gdb/valprint.c
> @@ -1232,11 +1232,11 @@ value_print (struct value *val, struct ui_file *stream,
> }
>
> /* Meant to be used in debug sessions, so don't export it in a header file. */
> -extern void ATTRIBUTE_UNUSED debug_val (struct value *val);
> +[[maybe_unused]] extern void debug_val (struct value *val);
>
> /* Print VAL. */
>
> -void ATTRIBUTE_UNUSED
> +[[maybe_unused]] void
> debug_val (struct value *val)
> {
> value_print (val, gdb_stdlog, &user_print_options);
> diff --git a/gdbserver/linux-aarch64-low.cc b/gdbserver/linux-aarch64-low.cc
> index a2588a6e2a9c..b68d39e1b803 100644
> --- a/gdbserver/linux-aarch64-low.cc
> +++ b/gdbserver/linux-aarch64-low.cc
> @@ -741,7 +741,7 @@ aarch64_target::low_new_fork (process_info *parent,
>
> static void
> aarch64_sve_regs_copy_to_regcache (struct regcache *regcache,
> - ATTRIBUTE_UNUSED const void *buf)
> + [[maybe_unused]] const void *buf)
> {
> /* BUF is unused here since we collect the data straight from a ptrace
> request in aarch64_sve_regs_copy_to_reg_buf, therefore bypassing
> @@ -776,7 +776,7 @@ aarch64_sve_regs_copy_from_regcache (struct regcache *regcache, void *buf)
>
> static void
> aarch64_za_regs_copy_to_regcache (struct regcache *regcache,
> - ATTRIBUTE_UNUSED const void *buf)
> + [[maybe_unused]] const void *buf)
> {
> /* BUF is unused here since we collect the data straight from a ptrace
> request, therefore bypassing gdbserver's own call to ptrace. */
> @@ -822,7 +822,7 @@ aarch64_za_regs_copy_from_regcache (struct regcache *regcache, void *buf)
>
> static void
> aarch64_zt_regs_copy_to_regcache (struct regcache *regcache,
> - ATTRIBUTE_UNUSED const void *buf)
> + [[maybe_unused]] const void *buf)
> {
> /* BUF is unused here since we collect the data straight from a ptrace
> request, therefore bypassing gdbserver's own call to ptrace. */
> diff --git a/gdbserver/x86-tdesc.h b/gdbserver/x86-tdesc.h
> index 4ed6d6635bbb..ce0c6c1be90d 100644
> --- a/gdbserver/x86-tdesc.h
> +++ b/gdbserver/x86-tdesc.h
> @@ -20,8 +20,8 @@
>
> /* The "expedite" registers for x86 targets. Since whether the
> variable is used depends on host/configuration, we mark it
> - ATTRIBUTE_UNUSED to keep it simple here. */
> -static const char *i386_expedite_regs[] ATTRIBUTE_UNUSED
> + [[maybe_unused]] to keep it simple here. */
> +[[maybe_unused]] static const char *i386_expedite_regs[]
> = {"ebp", "esp", "eip", NULL};
>
> #ifdef __x86_64__
> diff --git a/gdbsupport/safe-strerror.cc b/gdbsupport/safe-strerror.cc
> index d53cf84511fd..ad25cfc3d765 100644
> --- a/gdbsupport/safe-strerror.cc
> +++ b/gdbsupport/safe-strerror.cc
> @@ -26,14 +26,14 @@
> function. */
>
> /* Called if we have a XSI-compliant strerror_r. */
> -ATTRIBUTE_UNUSED static char *
> +[[maybe_unused]] static char *
> select_strerror_r (int res, char *buf)
> {
> return res == 0 ? buf : nullptr;
> }
>
> /* Called if we have a GNU strerror_r. */
> -ATTRIBUTE_UNUSED static char *
> +[[maybe_unused]] static char *
> select_strerror_r (char *res, char *)
> {
> return res;
> diff --git a/gdbsupport/thread-pool.cc b/gdbsupport/thread-pool.cc
> index 4dc72e566428..12329ea98831 100644
> --- a/gdbsupport/thread-pool.cc
> +++ b/gdbsupport/thread-pool.cc
> @@ -44,14 +44,14 @@
> takes a printf-style format and an argument. This wrapper handles the
> difference. */
>
> -ATTRIBUTE_UNUSED static void
> +[[maybe_unused]] static void
> do_set_thread_name (int (*set_name) (pthread_t, const char *, void *),
> const char *name)
> {
> set_name (pthread_self (), "%s", const_cast<char *> (name));
> }
>
> -ATTRIBUTE_UNUSED static void
> +[[maybe_unused]] static void
> do_set_thread_name (int (*set_name) (pthread_t, const char *),
> const char *name)
> {
> @@ -60,7 +60,7 @@ do_set_thread_name (int (*set_name) (pthread_t, const char *),
>
> /* The macOS man page says that pthread_setname_np returns "void", but
> the headers actually declare it returning "int". */
> -ATTRIBUTE_UNUSED static void
> +[[maybe_unused]] static void
> do_set_thread_name (int (*set_name) (const char *), const char *name)
> {
> set_name (name);
>
> base-commit: cdfda31c0d6b85cfff7fddeabffa570176161548
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] gdb, gdbserver, gdbsupport: use [[maybe_unused]] instead of ATTRIBUTE_UNUSED
2026-06-19 12:49 ` [PATCH 1/2] gdb, gdbserver, gdbsupport: use [[maybe_unused]] instead of ATTRIBUTE_UNUSED Tom de Vries
@ 2026-06-26 15:20 ` Tom Tromey
0 siblings, 0 replies; 4+ messages in thread
From: Tom Tromey @ 2026-06-26 15:20 UTC (permalink / raw)
To: Tom de Vries; +Cc: simon.marchi, gdb-patches
Tom> these both look fine to me.
Tom> Reviewed-By: Tom de Vries <tdevries@suse.de>
FWIW me too.
Approved-By: Tom Tromey <tom@tromey.com>
Tom
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-06-26 15:20 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH 2/2] gdb, gdbsupport: use [[nodiscard]] instead of ATTRIBUTE_UNUSED_RESULT simon.marchi
2026-06-19 12:49 ` [PATCH 1/2] gdb, gdbserver, gdbsupport: use [[maybe_unused]] instead of ATTRIBUTE_UNUSED Tom de Vries
2026-06-26 15:20 ` Tom Tromey
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox