|
220 | 220 | // GTEST_HAS_ALT_PATH_SEP_ - Always defined to 0 or 1. |
221 | 221 | // GTEST_WIDE_STRING_USES_UTF16_ - Always defined to 0 or 1. |
222 | 222 | // GTEST_HAS_MUTEX_AND_THREAD_LOCAL_ - Always defined to 0 or 1. |
223 | | -// GTEST_HAS_DOWNCAST_ - Always defined to 0 or 1. |
224 | 223 | // GTEST_HAS_NOTIFICATION_- Always defined to 0 or 1. |
225 | 224 | // |
226 | 225 | // Synchronization: |
|
313 | 312 | #include "gtest/internal/custom/gtest-port.h" |
314 | 313 | #include "gtest/internal/gtest-port-arch.h" |
315 | 314 |
|
316 | | -#ifndef GTEST_HAS_DOWNCAST_ |
317 | | -#define GTEST_HAS_DOWNCAST_ 0 |
318 | | -#endif |
319 | | - |
320 | 315 | #ifndef GTEST_HAS_MUTEX_AND_THREAD_LOCAL_ |
321 | 316 | #define GTEST_HAS_MUTEX_AND_THREAD_LOCAL_ 0 |
322 | 317 | #endif |
@@ -1153,17 +1148,12 @@ inline To ImplicitCast_(To x) { |
1153 | 1148 | // check to enforce this. |
1154 | 1149 | template <class Derived, class Base> |
1155 | 1150 | Derived* CheckedDowncastToActualType(Base* base) { |
| 1151 | + static_assert(std::is_base_of<Base, Derived>::value, |
| 1152 | + "target type not derived from source type"); |
1156 | 1153 | #if GTEST_HAS_RTTI |
1157 | | - GTEST_CHECK_(typeid(*base) == typeid(Derived)); |
1158 | | -#endif |
1159 | | - |
1160 | | -#if GTEST_HAS_DOWNCAST_ |
1161 | | - return ::down_cast<Derived*>(base); |
1162 | | -#elif GTEST_HAS_RTTI |
1163 | | - return dynamic_cast<Derived*>(base); // NOLINT |
1164 | | -#else |
1165 | | - return static_cast<Derived*>(base); // Poor man's downcast. |
| 1154 | + GTEST_CHECK_(base == nullptr || dynamic_cast<Derived*>(base) != nullptr); |
1166 | 1155 | #endif |
| 1156 | + return static_cast<Derived*>(base); |
1167 | 1157 | } |
1168 | 1158 |
|
1169 | 1159 | #if GTEST_HAS_STREAM_REDIRECTION |
|
0 commit comments