diff options
Diffstat (limited to 'runtime/base/casts.h')
| -rw-r--r-- | runtime/base/casts.h | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/runtime/base/casts.h b/runtime/base/casts.h index be94c2eb78..138c2fda80 100644 --- a/runtime/base/casts.h +++ b/runtime/base/casts.h @@ -19,6 +19,8 @@ #include <assert.h> #include <string.h> +#include <type_traits> + #include "base/macros.h" namespace art { @@ -65,16 +67,9 @@ inline To implicit_cast(From const &f) { template<typename To, typename From> // use like this: down_cast<T*>(foo); inline To down_cast(From* f) { // so we only accept pointers - // Ensures that To is a sub-type of From *. This test is here only - // for compile-time type checking, and has no overhead in an - // optimized build at run-time, as it will be optimized away - // completely. - if (false) { - implicit_cast<From*, To>(0); - } + static_assert(std::is_base_of<From, typename std::remove_pointer<To>::type>::value, + "down_cast unsafe as To is not a subtype of From"); - // - // assert(f == NULL || dynamic_cast<To>(f) != NULL); // RTTI: debug mode only! return static_cast<To>(f); } |