From: Simon Marchi Date: Tue, 31 Jan 2023 15:57:20 +0000 (-0500) Subject: gdbsupport: allow passing nullptr to checked_static_cast X-Git-Tag: binutils-2_41~2002 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d7789889b1839c3c0f64c6738b0d8517ccead049;p=thirdparty%2Fbinutils-gdb.git gdbsupport: allow passing nullptr to checked_static_cast Both static_cast and dynamic_cast handle nullptr (they return nullptr), so I think checked_static_cast should too. This will allow doing a null check after a checked_static_cast: cooked_index_vector *table = (gdb::checked_static_cast (per_bfd->index_table.get ())); if (table != nullptr) return; Change-Id: If5c3134e63696f8e417c87b5f3901240c9f7ea97 --- diff --git a/gdbsupport/gdb-checked-static-cast.h b/gdbsupport/gdb-checked-static-cast.h index cc298733fad..bc75244bddd 100644 --- a/gdbsupport/gdb-checked-static-cast.h +++ b/gdbsupport/gdb-checked-static-cast.h @@ -54,6 +54,9 @@ checked_static_cast (V *v) "types must be related"); #ifdef DEVELOPMENT + if (v == nullptr) + return nullptr; + T result = dynamic_cast (v); gdb_assert (result != nullptr); #else