[v2] Remove use of scoped_restore_tmpl from scoped_restore_warning_hook

Message ID 20240207111721.16314-1-ciaranwoodward@xmos.com
State Committed
Headers
Series [v2] Remove use of scoped_restore_tmpl from scoped_restore_warning_hook |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Testing passed

Commit Message

Ciaran Woodward Feb. 7, 2024, 11:17 a.m. UTC
  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(-)
  

Comments

Tom Tromey Feb. 7, 2024, 3:44 p.m. UTC | #1
>>>>> "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
  

Patch

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.  */