* [PATCH] Remove use of scoped_restore_tmpl from scoped_restore_warning_hook
@ 2024-02-06 18:22 Ciaran Woodward
2024-02-06 18:37 ` Tom Tromey
2024-02-07 11:17 ` [PATCH v2] " Ciaran Woodward
0 siblings, 2 replies; 5+ messages in thread
From: Ciaran Woodward @ 2024-02-06 18:22 UTC (permalink / raw)
To: gdb-patches; +Cc: tom, Aditya.Kamath1, Ciaran Woodward
The warning_hook_handler function pointer takes va_list as
an argument, which on some platforms (mingw64) includes some
attributes. Attributes get ignored in template arguments.
This led to the compiler warning:
error: ignoring attributes on template argument 'warning_hook_handler' {aka 'void (*)(const char*, char*)'} [-Werror=ignored-attributes]
387 | scoped_restore_tmpl<warning_hook_handler> m_save;
| ^
By manually implementing the save/restore behaviour, rather
than using the helper template, this warning is fixed.
---
This is a result of the discussion here:
https://sourceware.org/pipermail/gdb-patches/2024-February/206374.html
gdb/utils.c | 9 ++++++++-
gdb/utils.h | 15 ++++++++++++++-
2 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/gdb/utils.c b/gdb/utils.c
index 702c3f15826..40b998d6288 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -145,8 +145,15 @@ get_warning_hook_handler ()
scoped_restore_warning_hook::scoped_restore_warning_hook
(warning_hook_handler new_handler)
- : m_save (make_scoped_restore (&warning_hook, new_handler))
+ : m_save (warning_hook)
{
+ warning_hook = new_handler;
+}
+
+scoped_restore_warning_hook::~scoped_restore_warning_hook ()
+{
+ if (!m_moved)
+ warning_hook = m_save;
}
/* Print a warning message. The first argument STRING is the warning
diff --git a/gdb/utils.h b/gdb/utils.h
index 7487590902a..d3b8efa56cb 100644
--- a/gdb/utils.h
+++ b/gdb/utils.h
@@ -383,8 +383,21 @@ class scoped_restore_warning_hook
public:
explicit scoped_restore_warning_hook (warning_hook_handler new_handler);
+ scoped_restore_warning_hook (scoped_restore_warning_hook &other)
+ : m_save (other.m_save),
+ m_moved (other.m_moved)
+ {
+ other.m_moved = true;
+ }
+
+ ~scoped_restore_warning_hook ();
+
private:
- scoped_restore_tmpl<warning_hook_handler> m_save;
+ scoped_restore_warning_hook &operator= (const scoped_restore_warning_hook &)
+ = delete;
+
+ warning_hook_handler m_save;
+ bool m_moved = false;
};
/* Return the current warning handler. */
--
2.25.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Remove use of scoped_restore_tmpl from scoped_restore_warning_hook
2024-02-06 18:22 [PATCH] Remove use of scoped_restore_tmpl from scoped_restore_warning_hook Ciaran Woodward
@ 2024-02-06 18:37 ` Tom Tromey
2024-02-07 11:18 ` Ciaran Woodward
2024-02-07 11:17 ` [PATCH v2] " Ciaran Woodward
1 sibling, 1 reply; 5+ messages in thread
From: Tom Tromey @ 2024-02-06 18:37 UTC (permalink / raw)
To: Ciaran Woodward; +Cc: gdb-patches, tom, Aditya.Kamath1
>>>>> "Ciaran" == Ciaran Woodward <ciaranwoodward@xmos.com> writes:
Ciaran> By manually implementing the save/restore behaviour, rather
Ciaran> than using the helper template, this warning is fixed.
Thank you.
Ciaran> + warning_hook_handler m_save;
Ciaran> + bool m_moved = false;
Can we just delete the move constructor?
Tom
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2] Remove use of scoped_restore_tmpl from scoped_restore_warning_hook
2024-02-06 18:22 [PATCH] Remove use of scoped_restore_tmpl from scoped_restore_warning_hook Ciaran Woodward
2024-02-06 18:37 ` Tom Tromey
@ 2024-02-07 11:17 ` Ciaran Woodward
2024-02-07 15:44 ` Tom Tromey
1 sibling, 1 reply; 5+ messages in thread
From: Ciaran Woodward @ 2024-02-07 11:17 UTC (permalink / raw)
To: gdb-patches; +Cc: tom, Ciaran Woodward
The warning_hook_handler function pointer takes va_list as
an argument, which on some platforms (mingw64) includes some
attributes. Attributes get ignored in template arguments.
This led to the compiler warning:
error: ignoring attributes on template argument 'warning_hook_handler' {aka 'void (*)(const char*, char*)'} [-Werror=ignored-attributes]
387 | scoped_restore_tmpl<warning_hook_handler> m_save;
| ^
By manually implementing the save/restore behaviour, rather
than using the helper template, this warning is fixed.
---
gdb/utils.c | 8 +++++++-
gdb/utils.h | 9 ++++++++-
2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/gdb/utils.c b/gdb/utils.c
index 702c3f15826..a1aeb1025fa 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -145,8 +145,14 @@ get_warning_hook_handler ()
scoped_restore_warning_hook::scoped_restore_warning_hook
(warning_hook_handler new_handler)
- : m_save (make_scoped_restore (&warning_hook, new_handler))
+ : m_save (warning_hook)
{
+ warning_hook = new_handler;
+}
+
+scoped_restore_warning_hook::~scoped_restore_warning_hook ()
+{
+ warning_hook = m_save;
}
/* Print a warning message. The first argument STRING is the warning
diff --git a/gdb/utils.h b/gdb/utils.h
index 7487590902a..2acd1fc4624 100644
--- a/gdb/utils.h
+++ b/gdb/utils.h
@@ -383,8 +383,15 @@ class scoped_restore_warning_hook
public:
explicit scoped_restore_warning_hook (warning_hook_handler new_handler);
+ ~scoped_restore_warning_hook ();
+
private:
- scoped_restore_tmpl<warning_hook_handler> m_save;
+ scoped_restore_warning_hook (const scoped_restore_warning_hook &other)
+ = delete;
+ scoped_restore_warning_hook &operator= (const scoped_restore_warning_hook &)
+ = delete;
+
+ warning_hook_handler m_save;
};
/* Return the current warning handler. */
--
2.25.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* RE: [PATCH] Remove use of scoped_restore_tmpl from scoped_restore_warning_hook
2024-02-06 18:37 ` Tom Tromey
@ 2024-02-07 11:18 ` Ciaran Woodward
0 siblings, 0 replies; 5+ messages in thread
From: Ciaran Woodward @ 2024-02-07 11:18 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches, Aditya.Kamath1
> Can we just delete the move constructor?
Yes, done in v2 (sent to list)
Cheers,
Ciaran
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] Remove use of scoped_restore_tmpl from scoped_restore_warning_hook
2024-02-07 11:17 ` [PATCH v2] " Ciaran Woodward
@ 2024-02-07 15:44 ` Tom Tromey
0 siblings, 0 replies; 5+ messages in thread
From: Tom Tromey @ 2024-02-07 15:44 UTC (permalink / raw)
To: Ciaran Woodward; +Cc: gdb-patches, tom
>>>>> "Ciaran" == Ciaran Woodward <ciaranwoodward@xmos.com> writes:
Ciaran> The warning_hook_handler function pointer takes va_list as
Ciaran> an argument, which on some platforms (mingw64) includes some
Ciaran> attributes. Attributes get ignored in template arguments.
Ciaran> This led to the compiler warning:
Thanks for the patch. This is ok.
Approved-By: Tom Tromey <tom@tromey.com>
Tom
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-02-07 15:44 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-06 18:22 [PATCH] Remove use of scoped_restore_tmpl from scoped_restore_warning_hook Ciaran Woodward
2024-02-06 18:37 ` Tom Tromey
2024-02-07 11:18 ` Ciaran Woodward
2024-02-07 11:17 ` [PATCH v2] " Ciaran Woodward
2024-02-07 15:44 ` Tom Tromey
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).