Skip to content

Commit 1ed6a8c

Browse files
derekmaurocopybara-github
authored andcommitted
Remove unused cast implementation
PiperOrigin-RevId: 549456180 Change-Id: I10862e6de981087a5c590cccf6152255e9a176a0
1 parent d66ce58 commit 1ed6a8c

File tree

1 file changed

+0
-41
lines changed

1 file changed

+0
-41
lines changed

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

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,47 +1146,6 @@ inline To ImplicitCast_(To x) {
11461146
return x;
11471147
}
11481148

1149-
// When you upcast (that is, cast a pointer from type Foo to type
1150-
// SuperclassOfFoo), it's fine to use ImplicitCast_<>, since upcasts
1151-
// always succeed. When you downcast (that is, cast a pointer from
1152-
// type Foo to type SubclassOfFoo), static_cast<> isn't safe, because
1153-
// how do you know the pointer is really of type SubclassOfFoo? It
1154-
// could be a bare Foo, or of type DifferentSubclassOfFoo. Thus,
1155-
// when you downcast, you should use this macro. In debug mode, we
1156-
// use dynamic_cast<> to double-check the downcast is legal (we die
1157-
// if it's not). In normal mode, we do the efficient static_cast<>
1158-
// instead. Thus, it's important to test in debug mode to make sure
1159-
// the cast is legal!
1160-
// This is the only place in the code we should use dynamic_cast<>.
1161-
// In particular, you SHOULDN'T be using dynamic_cast<> in order to
1162-
// do RTTI (eg code like this:
1163-
// if (dynamic_cast<Subclass1>(foo)) HandleASubclass1Object(foo);
1164-
// if (dynamic_cast<Subclass2>(foo)) HandleASubclass2Object(foo);
1165-
// You should design the code some other way not to need this.
1166-
//
1167-
// This relatively ugly name is intentional. It prevents clashes with
1168-
// similar functions users may have (e.g., down_cast). The internal
1169-
// namespace alone is not enough because the function can be found by ADL.
1170-
template <typename To, typename From> // use like this: DownCast_<T*>(foo);
1171-
inline To DownCast_(From* f) { // so we only accept pointers
1172-
// Ensures that To is a sub-type of From *. This test is here only
1173-
// for compile-time type checking, and has no overhead in an
1174-
// optimized build at run-time, as it will be optimized away
1175-
// completely.
1176-
GTEST_INTENTIONAL_CONST_COND_PUSH_()
1177-
if (false) {
1178-
GTEST_INTENTIONAL_CONST_COND_POP_()
1179-
const To to = nullptr;
1180-
::testing::internal::ImplicitCast_<From*>(to);
1181-
}
1182-
1183-
#if GTEST_HAS_RTTI
1184-
// RTTI: debug mode only!
1185-
GTEST_CHECK_(f == nullptr || dynamic_cast<To>(f) != nullptr);
1186-
#endif
1187-
return static_cast<To>(f);
1188-
}
1189-
11901149
// Downcasts the pointer of type Base to Derived.
11911150
// Derived must be a subclass of Base. The parameter MUST
11921151
// point to a class of type Derived, not any subclass of it.

0 commit comments

Comments
 (0)