]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
gdb: use static_cast in gdb::checked_static_cast
authorAndrew Burgess <aburgess@redhat.com>
Wed, 6 Mar 2024 17:28:48 +0000 (17:28 +0000)
committerAndrew Burgess <aburgess@redhat.com>
Tue, 19 Mar 2024 14:41:42 +0000 (14:41 +0000)
commit7d18eb9983b00455fd2f3100d4de2772c3f656ad
tree3840f2765b637e6732f44d1f25b98026f1c67b22
parent709b8d140b47df446dd242450d558bad20780ebc
gdb: use static_cast in gdb::checked_static_cast

This commit:

  commit 6fe4779ac4b1874c995345e3eabd89cb1a05fbdf
  Date:   Sat Feb 24 11:00:20 2024 +0100

      [gdb/build] Fix static cast of virtual base

addressed an issue where GDB would not compile in production mode due
to a use of gdb::checked_static_cast.  The problem was that we were
asking GDB to cast from a virtual base class to a sub-class, this
works fine when using dynamic_cast, but does not work with
static_cast.

The gdb::checked_static_cast actually uses dynamic_cast under the hood
in development mode in order to ensure that the cast is valid, while
in a production build we use static_cast as this is more efficient.

What this meant however, was that when gdb::checked_static_cast was
used to cast from a virtual base class, the dynamic_cast of a
non-production build worked fine, while the production build's
static_cast caused a build failure.

However, the gdb::checked_static_cast function already contains some
static_assert calls that are intended to catch any issues with invalid
type casting, the goal of these asserts was to prevent issues like
this: the build only failing in production mode.  Clearly the current
asserts are not enough.

I don't think there is a std::is_virtual_base type trait check, so
what I propose instead is that in non-production mode we also make use
of static_cast.  This will ensure that any errors that crop up in
production mode should also be revealed in non-production mode, and
should catch issues like this in the future.

There should be no user visible changes after this commit.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31399

Co-Authored-By: Simon Marchi <simon.marchi@polymtl.ca>
gdbsupport/gdb-checked-static-cast.h