Skip to content

Commit

Permalink
More c++ lint fixes (#3400)
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardnormier authored Jan 22, 2025
1 parent d5bb07d commit f6faa9e
Show file tree
Hide file tree
Showing 67 changed files with 242 additions and 204 deletions.
13 changes: 8 additions & 5 deletions .clang-format-ignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# C++ code generated from Slice files
cpp/include/generated
cpp/src/**/generated
cpp/test/**/generated
cpp/src/**/msbuild/*
cpp/test/**/msbuild/*
cpp/include/generated/**/*.h
cpp/src/**/generated/**/*.cpp
cpp/test/**/generated/**/*.h
cpp/test/**/generated/**/*.cpp
cpp/src/**/msbuild/**/*.h
cpp/src/**/msbuild/**/*.cpp
cpp/test/**/msbuild/**/*.h
cpp/test/**/msbuild/**/*.cpp

# C++ code generated from the Bison/Flex parsers
cpp/src/Slice/Grammar.h
Expand Down
4 changes: 3 additions & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ Checks:
-modernize-concat-nested-namespaces,
-modernize-use-default-member-init,
performance-*,
-performance-avoid-endl
-performance-avoid-endl,
-performance-enum-size,
-performance-inefficient-string-concatenation,
'
WarningsAsErrors: '*'
HeaderFilterRegex: '.*'
Expand Down
4 changes: 2 additions & 2 deletions cpp/include/Ice/AsyncResponseHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ namespace IceInternal
}

void sendResponse(
std::function<void(Ice::OutputStream*)> marshal,
const std::function<void(Ice::OutputStream*)>& marshal,
std::optional<Ice::FormatType> format = std::nullopt) noexcept
{
// It is critical to only call the _sendResponse function only once. Calling it multiple times results in an
// incorrect dispatch count.
if (!_responseSent.test_and_set())
{
_sendResponse(makeOutgoingResponse(std::move(marshal), _current, format));
_sendResponse(makeOutgoingResponse(marshal, _current, format));
}
// else we ignore this call.
}
Expand Down
4 changes: 2 additions & 2 deletions cpp/include/Ice/Buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace IceInternal
Buffer(const Buffer&) = delete;
Buffer& operator=(const Buffer&) = delete;

void swapBuffer(Buffer& other)
void swapBuffer(Buffer& other) noexcept
{
b.swap(other.b);
std::swap(i, other.i);
Expand Down Expand Up @@ -83,7 +83,7 @@ namespace IceInternal

[[nodiscard]] bool ownsMemory() const noexcept { return _owned; }

void swap(Container&);
void swap(Container&) noexcept;

void clear();

Expand Down
2 changes: 1 addition & 1 deletion cpp/include/Ice/InputStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ namespace Ice
void read(PatchFunc patchFunc, void* patchAddr)
{
initEncaps();
_currentEncaps->decoder->read(patchFunc, patchAddr);
_currentEncaps->decoder->read(std::move(patchFunc), patchAddr);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion cpp/include/Ice/LocalExceptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ namespace Ice
int line,
std::string messagePrefix,
ErrorCode error,
std::function<std::string(ErrorCode)> errorToString);
const std::function<std::string(ErrorCode)>& errorToString);

/**
* Constructs a SyscallException without an error.
Expand Down
4 changes: 2 additions & 2 deletions cpp/include/Ice/MetricsAdminI.h
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ namespace IceInternal
{
return p->second->getFailures();
}
return IceMX::MetricsFailures();
return {};
}

std::pair<MetricsMapIPtr, SubMapMember> createSubMap(const std::string& subMapName)
Expand Down Expand Up @@ -403,7 +403,7 @@ namespace IceInternal
return std::make_shared<MetricsMapT<MetricsType>>(*this);
}

void detached(EntryTPtr entry)
void detached(const EntryTPtr& entry)
{
// This is called with the map mutex locked.

Expand Down
2 changes: 1 addition & 1 deletion cpp/include/Ice/MetricsObserverI.h
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ namespace IceMX
ObserverFactoryT(IceInternal::MetricsAdminIPtr metrics, const std::string& name)
: _metrics(std::move(metrics)),
_name(name),
_enabled(0)
_enabled{false}
{
_metrics->registerMap<MetricsType>(name, this);
}
Expand Down
14 changes: 7 additions & 7 deletions cpp/include/Ice/OutgoingAsync.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ namespace IceInternal
Ice::OperationMode,
std::optional<Ice::FormatType>,
const Ice::Context&,
std::function<void(Ice::OutputStream*)>);
const std::function<void(Ice::OutputStream*)>&);
void throwUserException();

Ice::OutputStream* startWriteParams(std::optional<Ice::FormatType> format)
Expand Down Expand Up @@ -299,7 +299,7 @@ namespace IceInternal
Ice::OperationMode mode,
std::optional<Ice::FormatType> format,
const Ice::Context& ctx,
std::function<void(Ice::OutputStream*)> write,
const std::function<void(Ice::OutputStream*)>& write,
std::function<void(const Ice::UserException&)> userException)
{
_read = [](Ice::InputStream* stream)
Expand All @@ -309,21 +309,21 @@ namespace IceInternal
return v;
};
_userException = std::move(userException);
OutgoingAsync::invoke(operation, mode, format, ctx, std::move(write));
OutgoingAsync::invoke(operation, mode, format, ctx, write);
}

void invoke(
std::string_view operation,
Ice::OperationMode mode,
std::optional<Ice::FormatType> format,
const Ice::Context& ctx,
std::function<void(Ice::OutputStream*)> write,
const std::function<void(Ice::OutputStream*)>& write,
std::function<void(const Ice::UserException&)> userException,
std::function<T(Ice::InputStream*)> read)
{
_read = std::move(read);
_userException = std::move(userException);
OutgoingAsync::invoke(operation, mode, format, ctx, std::move(write));
OutgoingAsync::invoke(operation, mode, format, ctx, write);
}

protected:
Expand All @@ -340,11 +340,11 @@ namespace IceInternal
Ice::OperationMode mode,
std::optional<Ice::FormatType> format,
const Ice::Context& ctx,
std::function<void(Ice::OutputStream*)> write,
const std::function<void(Ice::OutputStream*)>& write,
std::function<void(const Ice::UserException&)> userException)
{
_userException = std::move(userException);
OutgoingAsync::invoke(operation, mode, format, ctx, std::move(write));
OutgoingAsync::invoke(operation, mode, format, ctx, write);
}
};

Expand Down
2 changes: 1 addition & 1 deletion cpp/include/Ice/OutgoingResponse.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ namespace Ice
* @return The new response.
*/
ICE_API OutgoingResponse makeOutgoingResponse(
std::function<void(OutputStream*)> marshal,
const std::function<void(OutputStream*)>& marshal,
const Current& current,
std::optional<FormatType> format = std::nullopt) noexcept;

Expand Down
2 changes: 1 addition & 1 deletion cpp/src/Ice/BatchRequestQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ BatchRequestQueue::abortBatchRequest(OutputStream* os)
}

int
BatchRequestQueue::swap(OutputStream* os, bool& compress)
BatchRequestQueue::swap(OutputStream* os, bool& compress) noexcept
{
unique_lock lock(_mutex);
if (_batchRequestNum == 0)
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/Ice/BatchRequestQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace IceInternal
void finishBatchRequest(Ice::OutputStream*, const Ice::ObjectPrx&, std::string_view);
void abortBatchRequest(Ice::OutputStream*);

int swap(Ice::OutputStream*, bool&);
int swap(Ice::OutputStream*, bool&) noexcept;

void destroy(std::exception_ptr);
bool isEmpty();
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/Ice/Buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ IceInternal::Buffer::Container::~Container()
}

void
IceInternal::Buffer::Container::swap(Container& other)
IceInternal::Buffer::Container::swap(Container& other) noexcept
{
std::swap(_buf, other._buf);
std::swap(_size, other._size);
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/Ice/Communicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ Ice::Communicator::getValueFactoryManager() const noexcept
void
Ice::Communicator::postToClientThreadPool(function<void()> call)
{
_instance->clientThreadPool()->execute(call, nullptr);
_instance->clientThreadPool()->execute(std::move(call), nullptr);
}

::std::function<void()>
Expand All @@ -257,7 +257,7 @@ Ice::Communicator::flushBatchRequestsAsync(
{
}
};
auto outAsync = make_shared<CommunicatorFlushBatchLambda>(_instance, ex, sent);
auto outAsync = make_shared<CommunicatorFlushBatchLambda>(_instance, std::move(ex), std::move(sent));
static constexpr string_view operationName = "flushBatchRequests";
outAsync->invoke(operationName, compress);
return [outAsync]() { outAsync->cancel(); };
Expand Down
19 changes: 10 additions & 9 deletions cpp/src/Ice/ConnectionFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ IceInternal::OutgoingConnectionFactory::createAsync(
auto cb = make_shared<ConnectCallback>(
_instance,
shared_from_this(),
endpoints,
std::move(endpoints),
hasMore,
std::move(response),
std::move(exception),
Expand Down Expand Up @@ -338,7 +338,8 @@ IceInternal::OutgoingConnectionFactory::getDefaultObjectAdapter() const noexcept
}

void
IceInternal::OutgoingConnectionFactory::setDefaultObjectAdapter(ObjectAdapterPtr adapter) noexcept
IceInternal::OutgoingConnectionFactory::setDefaultObjectAdapter(
ObjectAdapterPtr adapter) noexcept // NOLINT(performance-unnecessary-value-param)
{
lock_guard lock(_mutex);
_defaultObjectAdapter = dynamic_pointer_cast<ObjectAdapterI>(adapter);
Expand Down Expand Up @@ -786,14 +787,14 @@ IceInternal::OutgoingConnectionFactory::handleConnectionException(exception_ptr
IceInternal::OutgoingConnectionFactory::ConnectCallback::ConnectCallback(
InstancePtr instance,
OutgoingConnectionFactoryPtr factory,
const vector<EndpointIPtr>& endpoints,
vector<EndpointIPtr> endpoints,
bool hasMore,
std::function<void(Ice::ConnectionIPtr, bool)> createConnectionResponse,
std::function<void(std::exception_ptr)> createConnectionException,
Ice::EndpointSelectionType selType)
: _instance(std::move(instance)),
_factory(std::move(factory)),
_endpoints(endpoints),
_endpoints(std::move(endpoints)),
_hasMore(hasMore),
_createConnectionResponse(std::move(createConnectionResponse)),
_createConnectionException(std::move(createConnectionException)),
Expand Down Expand Up @@ -981,8 +982,8 @@ IceInternal::OutgoingConnectionFactory::ConnectCallback::nextConnector()
Ice::ConnectionIPtr connection = _factory->createConnection(_iter->connector->connect(), *_iter);
auto self = shared_from_this();
connection->startAsync(
[self](ConnectionIPtr conn) { self->connectionStartCompleted(std::move(conn)); },
[self](ConnectionIPtr conn, exception_ptr ex) { self->connectionStartFailed(std::move(conn), ex); });
[self](const ConnectionIPtr& conn) { self->connectionStartCompleted(conn); },
[self](const ConnectionIPtr& conn, exception_ptr ex) { self->connectionStartFailed(conn, ex); });
}
catch (const Ice::LocalException& ex)
{
Expand Down Expand Up @@ -1439,8 +1440,8 @@ IceInternal::IncomingConnectionFactory::message(ThreadPoolCurrent& current)

auto self = shared_from_this();
connection->startAsync(
[self](ConnectionIPtr conn) { self->connectionStartCompleted(std::move(conn)); },
[self](ConnectionIPtr conn, exception_ptr ex) { self->connectionStartFailed(std::move(conn), ex); });
[self](const ConnectionIPtr& conn) { self->connectionStartCompleted(conn); },
[self](const ConnectionIPtr& conn, exception_ptr ex) { self->connectionStartFailed(conn, ex); });
}

void
Expand Down Expand Up @@ -1501,7 +1502,7 @@ IceInternal::IncomingConnectionFactory::toString() const
}
else
{
return string();
return {};
}
}

Expand Down
2 changes: 1 addition & 1 deletion cpp/src/Ice/ConnectionFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ namespace IceInternal
ConnectCallback(
InstancePtr,
OutgoingConnectionFactoryPtr,
const std::vector<EndpointIPtr>&,
std::vector<EndpointIPtr>,
bool,
std::function<void(Ice::ConnectionIPtr, bool)>,
std::function<void(std::exception_ptr)>,
Expand Down
19 changes: 6 additions & 13 deletions cpp/src/Ice/ConnectionI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,8 @@ Ice::ConnectionI::OutgoingMessage::completed(std::exception_ptr ex)

void
Ice::ConnectionI::startAsync(
function<void(Ice::ConnectionIPtr)> connectionStartCompleted,
function<void(Ice::ConnectionIPtr, exception_ptr)> connectionStartFailed)
function<void(const ConnectionIPtr&)> connectionStartCompleted,
function<void(const ConnectionIPtr&, exception_ptr)> connectionStartFailed)
{
try
{
Expand Down Expand Up @@ -1464,7 +1464,7 @@ Ice::ConnectionI::message(ThreadPoolCurrent& current)

if (!_hasExecutor) // Optimization, call upcall() directly if there's no executor.
{
upcall(std::move(connectionStartCompleted), std::move(sentCBs), std::move(messageUpcall), messageStream);
upcall(connectionStartCompleted, sentCBs, messageUpcall, messageStream);
}
else
{
Expand All @@ -1477,23 +1477,16 @@ Ice::ConnectionI::message(ThreadPoolCurrent& current)
connectionStartCompleted = std::move(connectionStartCompleted),
sentCBs = std::move(sentCBs),
messageUpcall = std::move(messageUpcall),
stream]()
{
self->upcall(
std::move(connectionStartCompleted),
std::move(sentCBs),
std::move(messageUpcall),
*stream);
},
stream]() { self->upcall(connectionStartCompleted, sentCBs, messageUpcall, *stream); },
self);
}
}

void
ConnectionI::upcall(
function<void(ConnectionIPtr)> connectionStartCompleted,
const function<void(ConnectionIPtr)>& connectionStartCompleted,
const vector<OutgoingMessage>& sentCBs,
function<bool(InputStream&)> messageUpcall,
const function<bool(InputStream&)>& messageUpcall,
InputStream& messageStream)
{
int completedUpcallCount = 0;
Expand Down
8 changes: 4 additions & 4 deletions cpp/src/Ice/ConnectionI.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ namespace Ice
};

void startAsync(
std::function<void(ConnectionIPtr)>,
std::function<void(Ice::ConnectionIPtr, std::exception_ptr)>);
std::function<void(const ConnectionIPtr&)>,
std::function<void(const ConnectionIPtr&, std::exception_ptr)>);
void activate();
void hold();
void destroy(DestructionReason);
Expand Down Expand Up @@ -213,9 +213,9 @@ namespace Ice
// or an upcall issued from an incoming message). The invocation sent callbacks and the message upcall might
// both be set.
void upcall(
std::function<void(ConnectionIPtr)> connectionStartCompleted,
const std::function<void(ConnectionIPtr)>& connectionStartCompleted,
const std::vector<OutgoingMessage>& sentMessages,
std::function<bool(InputStream&)> messageUpcall,
const std::function<bool(InputStream&)>& messageUpcall,
InputStream& messageStream);
void finish(bool);

Expand Down
Loading

0 comments on commit f6faa9e

Please sign in to comment.