Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unused internal::DownCast #19372

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/google/protobuf/extension_set_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ extern bool fully_verify_message_sets_opt_out;

namespace {

using ::google::protobuf::internal::DownCast;
using TestUtil::EqualsToSerialized;

// This test closely mirrors google/protobuf/compiler/cpp/unittest.cc
Expand Down
1 change: 0 additions & 1 deletion src/google/protobuf/map_test.inc
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ struct MapTestPeer {
};

namespace {
using internal::DownCast;

// Map API Test =====================================================

Expand Down
5 changes: 0 additions & 5 deletions src/google/protobuf/message_lite.h
Original file line number Diff line number Diff line change
Expand Up @@ -1200,11 +1200,6 @@ T* OnShutdownDelete(T* p) {
return p;
}

inline void AssertDownCast(const MessageLite& from, const MessageLite& to) {
ABSL_DCHECK(TypeId::Get(from) == TypeId::Get(to))
<< "Cannot downcast " << from.GetTypeName() << " to " << to.GetTypeName();
}

template <bool test_call, typename MessageLite>
PROTOBUF_ALWAYS_INLINE MessageLite* MessageCreator::PlacementNew(
const MessageLite* prototype_for_func,
Expand Down
31 changes: 0 additions & 31 deletions src/google/protobuf/port.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,37 +174,6 @@ struct ArenaInitialized {
explicit ArenaInitialized() = default;
};

template <typename To, typename From>
void AssertDownCast(From* from) {
static_assert(std::is_base_of<From, To>::value, "illegal DownCast");

#if defined(__cpp_concepts)
// Check that this function is not used to downcast message types.
// For those we should use {Down,Dynamic}CastTo{Message,Generated}.
static_assert(!requires {
std::derived_from<std::remove_pointer_t<To>,
typename std::remove_pointer_t<To>::MessageLite>;
});
#endif

#if PROTOBUF_RTTI
// RTTI: debug mode only!
assert(from == nullptr || dynamic_cast<To*>(from) != nullptr);
#endif
}

template <typename To, typename From>
inline To DownCast(From* f) {
AssertDownCast<std::remove_pointer_t<To>>(f);
return static_cast<To>(f);
}

template <typename ToRef, typename From>
inline ToRef DownCast(From& f) {
AssertDownCast<std::remove_reference_t<ToRef>>(&f);
return static_cast<ToRef>(f);
}

// Looks up the name of `T` via RTTI, if RTTI is available.
template <typename T>
inline absl::optional<absl::string_view> RttiTypeName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ namespace protobuf {
namespace {


using internal::DownCast;
using UNITTEST::ForeignMessage;
using UNITTEST::TestAllExtensions;
using UNITTEST::TestAllTypes;
Expand Down
Loading