Skip to content

Commit 96683ee

Browse files
derekmaurocopybara-github
authored andcommitted
Remove the GTEST_HAS_DOWNCAST_ customization point.
PiperOrigin-RevId: 553150809 Change-Id: I10d19a45a85c5f63a5e65dc322413307116e1c25
1 parent 58e37f7 commit 96683ee

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

googletest/include/gtest/internal/gtest-port.h

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@
220220
// GTEST_HAS_ALT_PATH_SEP_ - Always defined to 0 or 1.
221221
// GTEST_WIDE_STRING_USES_UTF16_ - Always defined to 0 or 1.
222222
// GTEST_HAS_MUTEX_AND_THREAD_LOCAL_ - Always defined to 0 or 1.
223-
// GTEST_HAS_DOWNCAST_ - Always defined to 0 or 1.
224223
// GTEST_HAS_NOTIFICATION_- Always defined to 0 or 1.
225224
//
226225
// Synchronization:
@@ -313,10 +312,6 @@
313312
#include "gtest/internal/custom/gtest-port.h"
314313
#include "gtest/internal/gtest-port-arch.h"
315314

316-
#ifndef GTEST_HAS_DOWNCAST_
317-
#define GTEST_HAS_DOWNCAST_ 0
318-
#endif
319-
320315
#ifndef GTEST_HAS_MUTEX_AND_THREAD_LOCAL_
321316
#define GTEST_HAS_MUTEX_AND_THREAD_LOCAL_ 0
322317
#endif
@@ -1153,17 +1148,12 @@ inline To ImplicitCast_(To x) {
11531148
// check to enforce this.
11541149
template <class Derived, class Base>
11551150
Derived* CheckedDowncastToActualType(Base* base) {
1151+
static_assert(std::is_base_of<Base, Derived>::value,
1152+
"target type not derived from source type");
11561153
#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);
11661155
#endif
1156+
return static_cast<Derived*>(base);
11671157
}
11681158

11691159
#if GTEST_HAS_STREAM_REDIRECTION

0 commit comments

Comments
 (0)