case amd_dbgapi_register_type::kind::INTEGER:
{
const auto &integer_type
- = static_cast<const amd_dbgapi_register_type_integer &> (type);
+ = gdb::checked_static_cast<const amd_dbgapi_register_type_integer &>
+ (type);
switch (integer_type.bit_size ())
{
case 32:
case amd_dbgapi_register_type::kind::VECTOR:
{
const auto &vector_type
- = static_cast<const amd_dbgapi_register_type_vector &> (type);
+ = gdb::checked_static_cast<const amd_dbgapi_register_type_vector &>
+ (type);
struct type *element_type
= amd_dbgapi_register_type_to_gdb_type (vector_type.element_type (),
gdbarch);
case amd_dbgapi_register_type::kind::FLAGS:
{
const auto &flags_type
- = static_cast<const amd_dbgapi_register_type_flags &> (type);
+ = gdb::checked_static_cast<const amd_dbgapi_register_type_flags &>
+ (type);
struct type *gdb_type
= arch_flags_type (gdbarch, flags_type.name ().c_str (),
flags_type.bit_size ());
case amd_dbgapi_register_type::kind::ENUM:
{
const auto &enum_type
- = static_cast<const amd_dbgapi_register_type_enum &> (type);
+ = gdb::checked_static_cast<const amd_dbgapi_register_type_enum &>
+ (type);
struct type *gdb_type
= (type_allocator (gdbarch)
.new_type (TYPE_CODE_ENUM, enum_type.bit_size (),
gdb_assert (type.kind () == amd_dbgapi_register_type::kind::FLAGS);
- const auto &f = static_cast<const amd_dbgapi_register_type_flags &> (type);
+ const auto &f
+ = gdb::checked_static_cast<const amd_dbgapi_register_type_flags &> (type);
gdb_assert (f.size () == 23);
/* Check the two "FP_ROUND" fields. */
== amd_dbgapi_register_type::kind::ENUM);
const auto &e
- = static_cast<const amd_dbgapi_register_type_enum &> (*field.type);
+ = gdb::checked_static_cast<const amd_dbgapi_register_type_enum &>
+ (*field.type);
gdb_assert (e.size () == 4);
gdb_assert (e[0].name == "NEAREST_EVEN");
gdb_assert (e[0].value == 0);
gdb_assert (f[22].type->kind () == amd_dbgapi_register_type::kind::INTEGER);
const auto &i
- = static_cast<const amd_dbgapi_register_type_integer &> (*f[22].type);
+ = gdb::checked_static_cast<const amd_dbgapi_register_type_integer &>
+ (*f[22].type);
gdb_assert (i.bit_size () == 32);
gdb_assert (i.is_unsigned ());
}
gdb_assert (type.kind () == amd_dbgapi_register_type::kind::VECTOR);
- const auto &v = static_cast<const amd_dbgapi_register_type_vector &> (type);
+ const auto &v
+ = gdb::checked_static_cast<const amd_dbgapi_register_type_vector &>
+ (type);
gdb_assert (v.count () == 64);
const auto &et = v.element_type ();
gdb_assert (et.kind () == amd_dbgapi_register_type::kind::INTEGER);
- const auto &i = static_cast<const amd_dbgapi_register_type_integer &> (et);
+ const auto &i
+ = gdb::checked_static_cast<const amd_dbgapi_register_type_integer &> (et);
gdb_assert (i.bit_size () == 32);
gdb_assert (!i.is_unsigned ());
}
return result;
}
+/* Same as the above, but to cast from a reference type to another. */
+
+template<typename T, typename V, typename = gdb::Requires<std::is_reference<T>>>
+T
+checked_static_cast (V &v)
+{
+ static_assert (std::is_reference<T>::value, "target must be a reference type");
+
+ using T_no_R = typename std::remove_reference<T>::type;
+ using T_P = typename std::add_pointer<T_no_R>::type;
+
+ using V_no_R = typename std::remove_reference<V>::type;
+
+ return *checked_static_cast<T_P, V_no_R> (&v);
+}
+
}
#endif /* COMMON_GDB_CHECKED_DYNAMIC_CAST_H */