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

Prefer dynamic_pointer_cast over dynamic_cast when casting shared_ptr #2899

Merged
merged 1 commit into from
Oct 15, 2024
Merged
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
2 changes: 1 addition & 1 deletion cpp/include/Ice/MetricsAdminI.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ namespace IceInternal
m = p->second.first;
}

MetricsMapT<MemberMetricsType>* map = dynamic_cast<MetricsMapT<MemberMetricsType>*>(m.get());
auto map = std::dynamic_pointer_cast<MetricsMapT<MemberMetricsType>>(m);
assert(map);
return map->getMatching(helper);
}
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/Ice/EndpointFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ IceInternal::UnderlyingEndpointFactory::initialize()
EndpointFactoryPtr factory = _instance->getEndpointFactory(_type);
if (factory)
{
EndpointFactoryWithUnderlying* f = dynamic_cast<EndpointFactoryWithUnderlying*>(factory.get());
auto f = dynamic_pointer_cast<EndpointFactoryWithUnderlying>(factory);
if (f)
{
_factory = f->cloneWithUnderlying(_instance, _underlying);
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/Ice/IPEndpointI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ IceInternal::IPEndpointI::withPublishedHost(string host) const
bool
IceInternal::IPEndpointI::equivalent(const EndpointIPtr& endpoint) const
{
const IPEndpointI* ipEndpointI = dynamic_cast<const IPEndpointI*>(endpoint.get());
auto ipEndpointI = dynamic_pointer_cast<IPEndpointI>(endpoint);
if (!ipEndpointI)
{
return false;
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/Ice/InputStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ IceInternal::Ex::throwUOE(const char* file, int line, const string& expectedType
// If the object is an unknown sliced object, we didn't find a
// value factory, in this case raise a MarshalException instead.
//
UnknownSlicedValue* usv = dynamic_cast<UnknownSlicedValue*>(v.get());
UnknownSlicedValuePtr usv = dynamic_pointer_cast<UnknownSlicedValue>(v);
if (usv)
{
throw MarshalException{
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/Ice/Instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1337,7 +1337,7 @@ IceInternal::Instance::finishSetup(int& argc, const char* argv[], const Ice::Com
// Load plug-ins.
//
assert(!_serverThreadPool);
PluginManagerI* pluginManagerImpl = dynamic_cast<PluginManagerI*>(_pluginManager.get());
auto pluginManagerImpl = dynamic_pointer_cast<PluginManagerI>(_pluginManager);
assert(pluginManagerImpl);
pluginManagerImpl->loadPlugins(argc, argv);

Expand Down
10 changes: 5 additions & 5 deletions cpp/src/Ice/InstrumentationI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ namespace
ThreadState newState;
};

IPConnectionInfo* getIPConnectionInfo(const ConnectionInfoPtr& info)
IPConnectionInfoPtr getIPConnectionInfo(const ConnectionInfoPtr& info)
{
for (ConnectionInfoPtr p = info; p; p = p->underlying)
{
IPConnectionInfo* ipInfo = dynamic_cast<IPConnectionInfo*>(p.get());
IPConnectionInfoPtr ipInfo = dynamic_pointer_cast<IPConnectionInfo>(p);
if (ipInfo)
{
return ipInfo;
Expand Down Expand Up @@ -101,7 +101,7 @@ namespace
if (_id.empty())
{
ostringstream os;
IPConnectionInfo* info = getIPConnectionInfo(_connectionInfo);
IPConnectionInfoPtr info = getIPConnectionInfo(_connectionInfo);
if (info)
{
os << info->localAddress << ':' << info->localPort;
Expand Down Expand Up @@ -850,7 +850,7 @@ CommunicatorObserverI::getConnectionObserver(
try
{
ConnectionObserverPtr delegate;
ConnectionObserverI* o = dynamic_cast<ConnectionObserverI*>(observer.get());
auto o = dynamic_pointer_cast<ConnectionObserverI>(observer);
if (_delegate)
{
delegate = _delegate->getConnectionObserver(con, endpt, state, o ? o->getDelegate() : observer);
Expand Down Expand Up @@ -878,7 +878,7 @@ CommunicatorObserverI::getThreadObserver(
try
{
ThreadObserverPtr delegate;
ThreadObserverI* o = dynamic_cast<ThreadObserverI*>(observer.get());
auto o = dynamic_pointer_cast<ThreadObserverI>(observer);
if (_delegate)
{
delegate = _delegate->getThreadObserver(parent, id, state, o ? o->getDelegate() : observer);
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/Ice/LoggerAdminI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -565,9 +565,9 @@ namespace
//
// There is currently no way to have a null local logger
//
assert(localLogger != 0);
assert(localLogger);

LoggerAdminLoggerI* wrapper = dynamic_cast<LoggerAdminLoggerI*>(localLogger.get());
auto wrapper = dynamic_pointer_cast<LoggerAdminLoggerI>(localLogger);
if (wrapper)
{
// use the underlying local logger
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/Ice/OutgoingAsync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ ProxyOutgoingAsyncBase::checkRetryAfterException(std::exception_ptr ex)

// If it's a fixed proxy, retrying isn't useful as the proxy is tied to
// the connection and the request will fail with the exception.
if (dynamic_cast<const FixedReference*>(ref.get()))
if (dynamic_pointer_cast<FixedReference>(ref))
{
rethrow_exception(ex);
}
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/Ice/Reference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1616,7 +1616,7 @@ IceInternal::RoutableReference::filterEndpoints(const vector<EndpointIPtr>& allE
remove_if(
endpoints.begin(),
endpoints.end(),
[](const EndpointIPtr& p) { return dynamic_cast<OpaqueEndpointI*>(p.get()) != 0; }),
[](const EndpointIPtr& p) { return dynamic_pointer_cast<OpaqueEndpointI>(p) != nullptr; }),
endpoints.end());

// Filter out endpoints according to the mode of the reference.
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/Ice/SSL/SSLEndpointI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ Ice::SSL::EndpointI::withPublishedHost(string host) const
bool
Ice::SSL::EndpointI::equivalent(const IceInternal::EndpointIPtr& endpoint) const
{
const EndpointI* endpointI = dynamic_cast<const EndpointI*>(endpoint.get());
auto endpointI = dynamic_pointer_cast<EndpointI>(endpoint);
if (!endpointI)
{
return false;
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/Ice/WSEndpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ IceInternal::WSEndpoint::withPublishedHost(string host) const
bool
IceInternal::WSEndpoint::equivalent(const EndpointIPtr& endpoint) const
{
const WSEndpoint* wsEndpointI = dynamic_cast<const WSEndpoint*>(endpoint.get());
auto wsEndpointI = dynamic_pointer_cast<WSEndpoint>(endpoint);
if (!wsEndpointI)
{
return false;
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/IceBT/EndpointI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ IceBT::EndpointI::withPublishedHost(string) const
bool
IceBT::EndpointI::equivalent(const IceInternal::EndpointIPtr& endpoint) const
{
const EndpointI* btEndpointI = dynamic_cast<const EndpointI*>(endpoint.get());
auto btEndpointI = dynamic_pointer_cast<EndpointI>(endpoint);
if (!btEndpointI)
{
return false;
Expand Down
2 changes: 1 addition & 1 deletion cpp/test/Ice/background/EndpointI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ EndpointI::withPublishedHost(string host) const
bool
EndpointI::equivalent(const IceInternal::EndpointIPtr& endpoint) const
{
const EndpointI* testEndpointI = dynamic_cast<const EndpointI*>(endpoint.get());
auto testEndpointI = dynamic_pointer_cast<EndpointI>(endpoint);
if (!testEndpointI)
{
return false;
Expand Down
4 changes: 2 additions & 2 deletions cpp/test/Ice/metrics/InstrumentationI.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ class CommunicatorObserverI final : public Ice::Instrumentation::CommunicatorObs
const Ice::Instrumentation::ConnectionObserverPtr& old) final
{
std::lock_guard lock(_mutex);
test(!old || dynamic_cast<ConnectionObserverI*>(old.get()));
test(!old || std::dynamic_pointer_cast<ConnectionObserverI>(old));
if (!connectionObserver)
{
connectionObserver = std::make_shared<ConnectionObserverI>();
Expand All @@ -287,7 +287,7 @@ class CommunicatorObserverI final : public Ice::Instrumentation::CommunicatorObs
const Ice::Instrumentation::ThreadObserverPtr& old) final
{
std::lock_guard lock(_mutex);
test(!old || dynamic_cast<ThreadObserverI*>(old.get()));
test(!old || std::dynamic_pointer_cast<ThreadObserverI>(old));
if (!threadObserver)
{
threadObserver = std::make_shared<ThreadObserverI>();
Expand Down
14 changes: 7 additions & 7 deletions cpp/test/Ice/optional/AllTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ allTests(Test::TestHelper* helper, bool)
Ice::ValuePtr obj;
in.read(obj);
in.endEncapsulation();
test(obj && dynamic_cast<TestObjectReader*>(obj.get()));
test(obj && dynamic_pointer_cast<TestObjectReader>(obj));
}

{
Expand All @@ -623,7 +623,7 @@ allTests(Test::TestHelper* helper, bool)
Ice::ValuePtr obj;
in.read(obj);
in.endEncapsulation();
test(obj && dynamic_cast<TestObjectReader*>(obj.get()));
test(obj && dynamic_pointer_cast<TestObjectReader>(obj));
factory->setEnabled(false);
}

Expand Down Expand Up @@ -693,7 +693,7 @@ allTests(Test::TestHelper* helper, bool)
Ice::ValuePtr obj;
in.read(obj);
in.endEncapsulation();
test(obj && dynamic_cast<TestObjectReader*>(obj.get()));
test(obj && dynamic_pointer_cast<TestObjectReader>(obj));
factory->setEnabled(false);
}

Expand Down Expand Up @@ -759,7 +759,7 @@ allTests(Test::TestHelper* helper, bool)
in.endEncapsulation();
factory->setEnabled(false);

rf = dynamic_cast<FObjectReader*>(obj.get())->getF();
rf = dynamic_pointer_cast<FObjectReader>(obj)->getF();
test(rf->fse.m == 56 && !rf->fsf);
}
cout << "ok" << endl;
Expand Down Expand Up @@ -795,7 +795,7 @@ allTests(Test::TestHelper* helper, bool)
Ice::ValuePtr obj;
in.read(obj);
in.endEncapsulation();
test(dynamic_cast<CObjectReader*>(obj.get()));
test(dynamic_pointer_cast<CObjectReader>(obj));
factory->setEnabled(false);
}

Expand All @@ -813,8 +813,8 @@ allTests(Test::TestHelper* helper, bool)
Ice::ValuePtr obj;
in.read(obj);
in.endEncapsulation();
test(obj && dynamic_cast<DObjectReader*>(obj.get()));
dynamic_cast<DObjectReader*>(obj.get())->check();
test(obj && dynamic_pointer_cast<DObjectReader>(obj));
dynamic_pointer_cast<DObjectReader>(obj)->check();
factory->setEnabled(false);
}
}
Expand Down
Loading