From 523b8d1de854cd74741b396cb9dd6c10427785fb Mon Sep 17 00:00:00 2001 From: Vas Crabb Date: Thu, 16 Jun 2016 17:35:02 +1000 Subject: [PATCH] Fix GCC6 warnings --- src/emu/addrmap.h | 2 -- src/emu/emucore.h | 66 +++++++++++++++++++++-------------------------- 2 files changed, 30 insertions(+), 38 deletions(-) diff --git a/src/emu/addrmap.h b/src/emu/addrmap.h index b9c1be94941..3bcea1a3f47 100644 --- a/src/emu/addrmap.h +++ b/src/emu/addrmap.h @@ -316,7 +316,6 @@ void ADDRESS_MAP_NAME(_name)(address_map &map, device_t &device) \ typedef write##_bits##_delegate write_delegate ATTR_UNUSED; \ address_map_entry##_bits *curentry = nullptr; \ (void)curentry; \ - assert(&device != nullptr); \ map.configure(_space, _bits); \ typedef _class drivdata_class ATTR_UNUSED; #define DEVICE_ADDRESS_MAP_START(_name, _bits, _class) \ @@ -326,7 +325,6 @@ void _class :: _name(::address_map &map, device_t &device) \ typedef write##_bits##_delegate write_delegate ATTR_UNUSED; \ address_map_entry##_bits *curentry = nullptr; \ (void)curentry; \ - assert(&device != nullptr); \ map.configure(AS_PROGRAM, _bits); \ typedef _class drivdata_class ATTR_UNUSED; #define ADDRESS_MAP_END \ diff --git a/src/emu/emucore.h b/src/emu/emucore.h index c8c95c1af48..530fb92dd12 100644 --- a/src/emu/emucore.h +++ b/src/emu/emucore.h @@ -28,6 +28,7 @@ // standard C++ includes #include +#include #include // core system includes @@ -312,48 +313,41 @@ class device_t; void report_bad_cast(const std::type_info &src_type, const std::type_info &dst_type); void report_bad_device_cast(const device_t *dev, const std::type_info &src_type, const std::type_info &dst_type); -// template function for casting from a base class to a derived class that is checked -// in debug builds and fast in release builds -template -inline _Dest downcast(_Source *src) +template +inline std::enable_if_t::value> report_bad_cast(Source *const src) { -#if defined(MAME_DEBUG) && !defined(MAME_DEBUG_FAST) - try { - if (dynamic_cast<_Dest>(src) != src) - { - if (dynamic_cast(src) != nullptr) - report_bad_device_cast(dynamic_cast(src), typeid(src), typeid(_Dest)); - else - report_bad_cast(typeid(src), typeid(_Dest)); - } - } - catch (std::bad_cast &) - { - report_bad_cast(typeid(src), typeid(_Dest)); - } -#endif - return static_cast<_Dest>(src); + if (src) report_bad_device_cast(src, typeid(Source), typeid(Dest)); + else report_bad_cast(typeid(Source), typeid(Dest)); } -template -inline _Dest downcast(_Source &src) +template +inline std::enable_if_t::value> report_bad_cast(Source *const src) +{ + device_t const *dev(dynamic_cast(src)); + if (dev) report_bad_device_cast(dev, typeid(Source), typeid(Dest)); + else report_bad_cast(typeid(Source), typeid(Dest)); +} + +// template function for casting from a base class to a derived class that is checked +// in debug builds and fast in release builds +template +inline Dest downcast(Source *src) { #if defined(MAME_DEBUG) && !defined(MAME_DEBUG_FAST) - try { - if (&dynamic_cast<_Dest>(src) != &src) - { - if (dynamic_cast(&src) != nullptr) - report_bad_device_cast(dynamic_cast(&src), typeid(src), typeid(_Dest)); - else - report_bad_cast(typeid(src), typeid(_Dest)); - } - } - catch (std::bad_cast &) - { - report_bad_cast(typeid(src), typeid(_Dest)); - } + Dest const chk(dynamic_cast(src)); + if (!chk || (chk != src)) report_bad_cast, Source>(src); #endif - return static_cast<_Dest>(src); + return static_cast(src); +} + +template +inline Dest downcast(Source &src) +{ +#if defined(MAME_DEBUG) && !defined(MAME_DEBUG_FAST) + std::remove_reference_t *const chk(dynamic_cast *>(&src)); + if (!chk || (chk != &src)) report_bad_cast, Source>(&src); +#endif + return static_cast(src); }