aboutsummaryrefslogtreecommitdiff
path: root/gdb/ui-file.c
diff options
context:
space:
mode:
authorAndrew Burgess <aburgess@redhat.com>2022-10-27 15:20:10 +0100
committerAndrew Burgess <aburgess@redhat.com>2022-11-28 19:23:30 +0000
commit5975a5caceb238be7eddb3b279d51145a1628af8 (patch)
treefe09fb5762ea84c77cbb70884769ba45274cdf56 /gdb/ui-file.c
parent8eb7d135e32ad6b7cdcfeffe486b195058206cdb (diff)
downloadgdb-5975a5caceb238be7eddb3b279d51145a1628af8.zip
gdb-5975a5caceb238be7eddb3b279d51145a1628af8.tar.gz
gdb-5975a5caceb238be7eddb3b279d51145a1628af8.tar.bz2
gdb: mark disassembler function callback types as noexcept
In disasm.h we define a set of types that are used by the various disassembler classes to hold callback functions before passing the callbacks into libopcodes. Because libopcodes is C code, and on some (many?) targets, C code is compiled without exception support, it is important that GDB not try to throw an exception over libopcode code. In the previous commit all the existing callbacks were marked as noexcept, however, this doesn't protect us from a future change to GDB either adding a new callback that is not noexcept, or removing the noexcept keyword from an existing callback. In this commit I mark all the callback types as noexcept. This means that GDB's disassembler classes will no longer compile if we try to pass a callback that is not marked as noexcept. At least, that's the idea. Unfortunately, it's not that easy. Before C++17, the noexcept keyword on a function typedef would be ignored, thus: using func_type = void (*) (void) noexcept; void a_func () { throw 123; } void some_func (func_type f) { f (); } int main () { some_func (a_func); return 0; } Will compile just fine for C++11 and C++14 with GCC. Clang on the other hand complains that 'noexcept' should not appear on function types, but then does appear to correctly complain that passing a_func is a mismatch in the set of exceptions that could be thrown. Switching to C++17 and both GCC and Clang correctly point out that passing a_func is an invalid conversion relating to the noexcept keyword. Changing a_func to: void a_func () noexcept { /* Nothing. */ } And for C++17 both GCC and Clang compile this just fine. My conclusion then is that adding the noexcept keyword to the function types is pointless while GDB is not compiled as C++17, and silencing the warnings would require us to jump through a bunch of hoops. And so, in this commit, I define a macro LIBOPCODE_CALLBACK_NOEXCEPT, this macro expands to noexcept when compiling for C++17, but otherwise expands to nothing. I then add this macro to the function types. I've compiled GDB as the default C++11 and also forced the compile to C++17. When compiling as C++17 I spotted a few additional places where callbacks needed to be marked noexcept (these fixes were merged into the previous commit, but this confirmed to be that the macro is working as expected).
Diffstat (limited to 'gdb/ui-file.c')
0 files changed, 0 insertions, 0 deletions