aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gdbsupport/gdb-checked-static-cast.h12
1 files changed, 4 insertions, 8 deletions
diff --git a/gdbsupport/gdb-checked-static-cast.h b/gdbsupport/gdb-checked-static-cast.h
index 227010e..24fa7a4 100644
--- a/gdbsupport/gdb-checked-static-cast.h
+++ b/gdbsupport/gdb-checked-static-cast.h
@@ -54,16 +54,12 @@ checked_static_cast (V *v)
"types must be related");
#ifdef DEVELOPMENT
- if (v == nullptr)
- return nullptr;
-
- T result = dynamic_cast<T> (v);
- gdb_assert (result != nullptr);
-#else
- T result = static_cast<T> (v);
+ gdb_assert (v == nullptr || dynamic_cast<T> (v) != nullptr);
#endif
- return result;
+ /* If a base class of V is virtual then the dynamic_cast above will
+ succeed, but this static_cast will fail. */
+ return static_cast<T> (v);
}
/* Same as the above, but to cast from a reference type to another. */