From eafdb96d56cce530d96899a512ea22e113830e5c Mon Sep 17 00:00:00 2001 From: Andreas Gampe Date: Thu, 23 Oct 2014 11:24:08 -0700 Subject: [PATCH] ART: Use static_assert in down_cast Use C++11 to write an actual compile-time assert. Change-Id: I36bd94adbf6c732e103720308e1e6bf11065f474 --- runtime/base/casts.h | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/runtime/base/casts.h b/runtime/base/casts.h index be94c2eb7..138c2fda8 100644 --- a/runtime/base/casts.h +++ b/runtime/base/casts.h @@ -19,6 +19,8 @@ #include #include +#include + #include "base/macros.h" namespace art { @@ -65,16 +67,9 @@ inline To implicit_cast(From const &f) { template // use like this: down_cast(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(0); - } + static_assert(std::is_base_of::type>::value, + "down_cast unsafe as To is not a subtype of From"); - // - // assert(f == NULL || dynamic_cast(f) != NULL); // RTTI: debug mode only! return static_cast(f); } -- 2.11.0