diff options
author | Andreas Gampe <agampe@google.com> | 2014-10-23 11:24:08 -0700 |
---|---|---|
committer | Andreas Gampe <agampe@google.com> | 2014-10-23 11:29:41 -0700 |
commit | eafdb96d56cce530d96899a512ea22e113830e5c (patch) | |
tree | 11bb0374f923a602de9a0fe77951524d6951e18e /runtime/base | |
parent | 98c171127c55cfd339458d96a2d3b7b8912474c1 (diff) | |
download | art-eafdb96d56cce530d96899a512ea22e113830e5c.zip art-eafdb96d56cce530d96899a512ea22e113830e5c.tar.gz art-eafdb96d56cce530d96899a512ea22e113830e5c.tar.bz2 |
ART: Use static_assert in down_cast
Use C++11 to write an actual compile-time assert.
Change-Id: I36bd94adbf6c732e103720308e1e6bf11065f474
Diffstat (limited to 'runtime/base')
-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 be94c2e..138c2fd 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); } |