diff options
author | Tom Tromey <tromey@adacore.com> | 2024-04-09 08:54:58 -0600 |
---|---|---|
committer | Tom Tromey <tromey@adacore.com> | 2024-04-15 09:21:40 -0600 |
commit | 75670e0075df0f6fc8c324ea11de193a038274d6 (patch) | |
tree | 51dc4ba098d49dcf771c17fe82b4c298496f7423 /gdb/utils.h | |
parent | bdcd50f901e3db5b773b6462813a50b9649aad57 (diff) | |
download | gdb-75670e0075df0f6fc8c324ea11de193a038274d6.zip gdb-75670e0075df0f6fc8c324ea11de193a038274d6.tar.gz gdb-75670e0075df0f6fc8c324ea11de193a038274d6.tar.bz2 |
Avoid complaint warning on mingw
The mingw build currently issues a warning:
./../../src/gdb/utils.h:378:56: warning: ignoring attributes on template argument 'void(const char*, va_list)' {aka 'void(const char*, char*)'} [-Wignored-attributes]
This patch fixes the problem as suggested by Simon:
https://sourceware.org/pipermail/gdb-patches/2024-April/207908.html
...that is, by changing the warning interceptor to a class with a
single 'warn' method.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Diffstat (limited to 'gdb/utils.h')
-rw-r--r-- | gdb/utils.h | 38 |
1 files changed, 18 insertions, 20 deletions
diff --git a/gdb/utils.h b/gdb/utils.h index 875a258..9635089 100644 --- a/gdb/utils.h +++ b/gdb/utils.h @@ -374,8 +374,19 @@ assign_return_if_changed (T &lval, const T &val) return true; } -/* A function that can be used to intercept warnings. */ -typedef gdb::function_view<void (const char *, va_list)> warning_hook_handler; +/* A class that can be used to intercept warnings. A class is used + here, rather than a gdb::function_view because it proved difficult + to use a function view in conjunction with ATTRIBUTE_PRINTF in a + way that would satisfy all compilers on all systems. And, even + though gdb only ever uses deferred_warnings here, a virtual + function is used to help Insight. */ +struct warning_hook_handler_type +{ + virtual void warn (const char *format, va_list args) ATTRIBUTE_PRINTF (2, 0) + = 0; +}; + +typedef warning_hook_handler_type *warning_hook_handler; /* Set the thread-local warning hook, and restore the old value when finished. */ @@ -418,7 +429,7 @@ extern warning_hook_handler get_warning_hook_handler (); instance of this class with the 'warn' function, and all warnings can be emitted with a single call to 'emit'. */ -struct deferred_warnings +struct deferred_warnings final : public warning_hook_handler_type { deferred_warnings () : m_can_style (gdb_stderr->can_emit_style_escape ()) @@ -426,36 +437,23 @@ struct deferred_warnings } /* Add a warning to the list of deferred warnings. */ - void warn (const char *format, ...) ATTRIBUTE_PRINTF(2,3) + void warn (const char *format, ...) ATTRIBUTE_PRINTF (2, 3) { - /* Generate the warning text into a string_file. */ - string_file msg (m_can_style); - va_list args; va_start (args, format); - msg.vprintf (format, args); + this->warn (format, args); va_end (args); - - /* Move the text into the list of deferred warnings. */ - m_warnings.emplace_back (std::move (msg)); } /* A variant of 'warn' so that this object can be used as a warning hook; see scoped_restore_warning_hook. Note that no locking is done, so users have to be careful to only install this into a single thread at a time. */ - void operator() (const char *format, va_list args) + void warn (const char *format, va_list args) override + ATTRIBUTE_PRINTF (2, 0) { string_file msg (m_can_style); - /* Clang warns if we add ATTRIBUTE_PRINTF to this method (because - the function-view wrapper doesn't also have the attribute), but - then warns again if we remove it, because this vprintf call - does not use a literal format string. So, suppress the - warnings here. */ - DIAGNOSTIC_PUSH - DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL msg.vprintf (format, args); - DIAGNOSTIC_POP m_warnings.emplace_back (std::move (msg)); } |