[PATCH 9/9] Unify the DWARF index holders

Tom Tromey tom@tromey.com
Wed Apr 20 12:53:26 GMT 2022


>>>>> "Pedro" == Pedro Alves <pedro@palves.net> writes:

>> +  mapped_index *index = (dynamic_cast<mapped_index *>
>> +			 (per_objfile->per_bfd->index_table.get ()));

Pedro> The patch uses dynamic_cast throughout, when you know the cast must succeed,
Pedro> which seems strange.

I tend to do that as a form of error checking.

In an older project of mine I had something like:

    template<typename T, V>
    T *
    assert_cast (V *v)
    {
      T *result = dynamic_cast<V *> (v);
      gdb_assert (result != nullptr);
      return result;
    }

... ensuring that these "must succeed" casts really do succeed.

Pedro> I think it would be better to use static_cast instead.

I can do that, though what do you think of the assert_cast thing?

Tom


More information about the Gdb-patches mailing list