Skip to content

Commit

Permalink
Remove use of scoped_restore_tmpl from scoped_restore_warning_hook
Browse files Browse the repository at this point in the history
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.

Approved-By: Tom Tromey <[email protected]>
  • Loading branch information
CiaranWoodward committed Feb 7, 2024
1 parent c33ea11 commit 6fb9966
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
8 changes: 7 additions & 1 deletion gdb/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion gdb/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down

0 comments on commit 6fb9966

Please sign in to comment.