From 0ca97379d3b471fff32c59104c412976ad8b1d05 Mon Sep 17 00:00:00 2001 From: Joe George Date: Tue, 4 Jun 2024 13:08:24 -0400 Subject: [PATCH] Add clang tidy and CI (#216) --- .clang-tidy | 17 +++++++ .github/workflows/clang_tidy.yml | 65 ++++++++++++++++++++++++ cpp/Chat/client/ChatUtils.cpp | 5 +- cpp/Chat/client/Client.cpp | 6 +-- cpp/Chat/client/PollingClient.cpp | 1 + cpp/Chat/server/ChatSessionI.cpp | 13 +++-- cpp/Chat/server/ChatUtils.cpp | 5 +- cpp/Chat/server/PollingChatSessionI.cpp | 12 ++--- cpp/Glacier2/callback/Client.cpp | 2 +- cpp/Glacier2/simpleChat/ChatSessionI.cpp | 6 +-- cpp/Glacier2/simpleChat/Client.cpp | 6 +-- cpp/Glacier2/simpleChat/Server.cpp | 4 +- cpp/Ice/async/Client.cpp | 2 +- cpp/Ice/asyncInvocation/Client.cpp | 2 +- cpp/Ice/bidir/CallbackI.cpp | 6 +-- cpp/Ice/bidir/CallbackI.h | 2 +- cpp/Ice/interleaved/ThroughputI.cpp | 2 +- cpp/Ice/invoke/Client.cpp | 6 +-- cpp/Ice/locator/Locator.cpp | 6 ++- cpp/Ice/mtalk/Client.cpp | 8 +-- cpp/Ice/nested/Client.cpp | 2 +- cpp/Ice/optional/ContactDBI.cpp | 12 ++--- cpp/Ice/plugin/HelloPluginI.cpp | 12 ++--- cpp/Ice/plugin/LoggerPluginI.cpp | 14 ++--- cpp/Ice/properties/Server.cpp | 6 +-- cpp/Ice/session/SessionI.cpp | 8 +-- cpp/Ice/throughput/ThroughputI.cpp | 12 ++--- cpp/IceGrid/customLocator/Locator.cpp | 6 ++- cpp/IceGrid/replication/HelloI.cpp | 2 +- cpp/IceGrid/replication/HelloI.h | 8 +-- cpp/IceGrid/sessionActivation/HelloI.cpp | 2 +- cpp/IceGrid/sessionActivation/HelloI.h | 8 +-- cpp/IceGrid/simple/HelloI.cpp | 2 +- cpp/IceGrid/simple/HelloI.h | 8 +-- cpp/IceStorm/clock/Publisher.cpp | 2 +- cpp/IceStorm/clock/Subscriber.cpp | 6 +-- cpp/IceStorm/replicated/Publisher.cpp | 2 +- cpp/IceStorm/replicated/Subscriber.cpp | 2 +- cpp/IceStorm/replicated2/Publisher.cpp | 2 +- cpp/IceStorm/replicated2/Subscriber.cpp | 6 +-- cpp/Manual/printer/Server.cpp | 4 +- 41 files changed, 199 insertions(+), 103 deletions(-) create mode 100644 .clang-tidy create mode 100644 .github/workflows/clang_tidy.yml diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 000000000..6c575607d --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,17 @@ +Checks: +'-*, + clang-analyzer-*, + -clang-diagnostic-shadow-uncaptured-local, + cert-*, + modernize-*, + -modernize-avoid-c-arrays, + -modernize-use-trailing-return-type, + performance-*, + -performance-avoid-endl +' +WarningsAsErrors: '' +HeaderFilterRegex: '' +UseColor: true +FormatStyle: 'file' +CheckOptions: + - { key: modernize-use-nullptr.NullMacros, value: 'NULL' } diff --git a/.github/workflows/clang_tidy.yml b/.github/workflows/clang_tidy.yml new file mode 100644 index 000000000..82b4b4795 --- /dev/null +++ b/.github/workflows/clang_tidy.yml @@ -0,0 +1,65 @@ +name: Clang Tidy + +on: + workflow_dispatch: + push: + branches: ["main"] + pull_request: + # The branches below must be a subset of the branches above + branches: ["main"] + +jobs: + clang-tidy: + runs-on: ubuntu-latest + steps: + - name: Install clang-tidy + run: | + # This LLVM script will add the relevant LLVM PPA: https://apt.llvm.org/ + wget https://apt.llvm.org/llvm.sh -O /tmp/llvm.sh + chmod +x /tmp/llvm.sh + sudo /tmp/llvm.sh 18 + sudo apt-get install -y clang-tidy-18 + rm /tmp/llvm.sh + clang-tidy-18 --version + + - name: Install bear + run: | + sudo apt-get update + sudo apt-get install -y bear + bear --version + + - name: Checkout Ice + uses: actions/checkout@v4 + with: + repository: zeroc-ice/ice + ref: main + path: ice + + - name: Setup Ice Build Dependencies + uses: ./ice/.github/actions/setup-dependencies + + - name: Build Ice + uses: ./ice/.github/actions/build + timeout-minutes: 90 + with: + working_directory: ice/cpp + build_flags: srcs + + - name: Set ICE_HOME + run: | + echo "ICE_HOME=${{ github.workspace }}/ice" >> $GITHUB_ENV + + - name: Checkout repository + uses: actions/checkout@v4 + with: + path: ice-demos + + - name: Build C++ Demos + timeout-minutes: 30 + working-directory: ice-demos/cpp + run: bear -- make + + - name: Run Clang Tidy + working-directory: ice-demos/cpp + run: | + find . -name "*.h" -o -name "*.cpp" | xargs run-clang-tidy-18 -j$(nproc) -quiet diff --git a/cpp/Chat/client/ChatUtils.cpp b/cpp/Chat/client/ChatUtils.cpp index 7e29f9da7..5490be2b0 100644 --- a/cpp/Chat/client/ChatUtils.cpp +++ b/cpp/Chat/client/ChatUtils.cpp @@ -4,12 +4,13 @@ #include #include +#include using namespace std; -using HtmlEntity = pair; +using HtmlEntity = pair; -static const HtmlEntity htmlEntities[] = { +constexpr std::array htmlEntities = { HtmlEntity(""", "\""), HtmlEntity("'", "'"), HtmlEntity("<", "<"), diff --git a/cpp/Chat/client/Client.cpp b/cpp/Chat/client/Client.cpp index 926b0d4d6..3de39b6f1 100644 --- a/cpp/Chat/client/Client.cpp +++ b/cpp/Chat/client/Client.cpp @@ -63,7 +63,7 @@ class ChatRoomCallbackI final : public Chat::ChatRoomCallback }; Chat::ChatSessionPrx -createSession(Glacier2::RouterPrx router) +createSession(const Glacier2::RouterPrx& router) { while (true) { @@ -87,7 +87,7 @@ createSession(Glacier2::RouterPrx router) throw runtime_error("Glaicer2::createSession return null. Is the SessionManager configured?"); } router->ice_getCachedConnection()->setCloseCallback( - [](Ice::ConnectionPtr) + [](const Ice::ConnectionPtr&) { const lock_guard lock(coutMutex); cout << "The Glacier2 session has been destroyed." << endl; @@ -110,7 +110,7 @@ createSession(Glacier2::RouterPrx router) } void -run(shared_ptr communicator) +run(const shared_ptr& communicator) { optional router{communicator->getDefaultRouter()}; if (!router) diff --git a/cpp/Chat/client/PollingClient.cpp b/cpp/Chat/client/PollingClient.cpp index 9b3d37f68..6e6903a04 100644 --- a/cpp/Chat/client/PollingClient.cpp +++ b/cpp/Chat/client/PollingClient.cpp @@ -105,6 +105,7 @@ class GetUpdatesTask } } + [[nodiscard]] bool isDone() const { const lock_guard lock(const_cast(_mutex)); diff --git a/cpp/Chat/server/ChatSessionI.cpp b/cpp/Chat/server/ChatSessionI.cpp index 34026f909..a0b2bdc35 100644 --- a/cpp/Chat/server/ChatSessionI.cpp +++ b/cpp/Chat/server/ChatSessionI.cpp @@ -29,7 +29,7 @@ class SessionCallbackAdapter : public ChatRoomCallbackAdapter, public enable_sha auto self = shared_from_this(); try { - _callback->initAsync(users, nullptr, [self](exception_ptr) { self->failed(); }); + _callback->initAsync(users, nullptr, [self](const exception_ptr&) { self->failed(); }); } catch (const Ice::CommunicatorDestroyedException&) { @@ -42,7 +42,7 @@ class SessionCallbackAdapter : public ChatRoomCallbackAdapter, public enable_sha auto self = shared_from_this(); try { - _callback->joinAsync(e->timestamp, e->name, nullptr, [self](exception_ptr) { self->failed(); }); + _callback->joinAsync(e->timestamp, e->name, nullptr, [self](const exception_ptr&) { self->failed(); }); } catch (const Ice::CommunicatorDestroyedException&) { @@ -55,7 +55,7 @@ class SessionCallbackAdapter : public ChatRoomCallbackAdapter, public enable_sha auto self = shared_from_this(); try { - _callback->leaveAsync(e->timestamp, e->name, nullptr, [self](exception_ptr) { self->failed(); }); + _callback->leaveAsync(e->timestamp, e->name, nullptr, [self](const exception_ptr&) { self->failed(); }); } catch (const Ice::CommunicatorDestroyedException&) { @@ -68,7 +68,12 @@ class SessionCallbackAdapter : public ChatRoomCallbackAdapter, public enable_sha auto self = shared_from_this(); try { - _callback->sendAsync(e->timestamp, e->name, e->message, nullptr, [self](exception_ptr) { self->failed(); }); + _callback->sendAsync( + e->timestamp, + e->name, + e->message, + nullptr, + [self](const exception_ptr&) { self->failed(); }); } catch (const Ice::CommunicatorDestroyedException&) { diff --git a/cpp/Chat/server/ChatUtils.cpp b/cpp/Chat/server/ChatUtils.cpp index db0c44102..d23fce054 100644 --- a/cpp/Chat/server/ChatUtils.cpp +++ b/cpp/Chat/server/ChatUtils.cpp @@ -12,9 +12,8 @@ using namespace std; static const unsigned int maxNameSize = 12; static const unsigned int minNameSize = 3; -static const string nameRange = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"; -static const string isEmptyTokens = "\t\r\n\f\v "; - +constexpr string_view nameRange = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"; +constexpr string_view isEmptyTokens = "\t\r\n\f\v "; static const unsigned int maxMessageSize = 1024; string diff --git a/cpp/Chat/server/PollingChatSessionI.cpp b/cpp/Chat/server/PollingChatSessionI.cpp index 5d1f0504f..e29a1e2ac 100644 --- a/cpp/Chat/server/PollingChatSessionI.cpp +++ b/cpp/Chat/server/PollingChatSessionI.cpp @@ -7,28 +7,28 @@ using namespace std; -class PollCallbackAdapter : public ChatRoomCallbackAdapter +class PollCallbackAdapter final : public ChatRoomCallbackAdapter { public: - virtual void init(Ice::StringSeq users) override + void init(Ice::StringSeq users) final { const lock_guard sync(_mutex); _users = std::move(users); } - virtual void send(const shared_ptr& e) override + void send(const shared_ptr& e) final { const lock_guard sync(_mutex); _updates.push_back(e); } - virtual void join(const shared_ptr& e) override + void join(const shared_ptr& e) final { const lock_guard sync(_mutex); _updates.push_back(e); } - virtual void leave(const shared_ptr& e) override + void leave(const shared_ptr& e) final { const lock_guard sync(_mutex); _updates.push_back(e); @@ -129,7 +129,7 @@ PollingChatSessionI::send(string message, const Ice::Current&) } throw Chat::InvalidMessageException(ex.what()); } - return _chatRoom->send(_name, std::move(msg)); + return _chatRoom->send(_name, msg); } void diff --git a/cpp/Glacier2/callback/Client.cpp b/cpp/Glacier2/callback/Client.cpp index e24db395b..1deada851 100644 --- a/cpp/Glacier2/callback/Client.cpp +++ b/cpp/Glacier2/callback/Client.cpp @@ -104,7 +104,7 @@ run(const shared_ptr& communicator) const Ice::ConnectionPtr connection = router->ice_getCachedConnection(); assert(connection); - connection->setCloseCallback([](Ice::ConnectionPtr) + connection->setCloseCallback([](const Ice::ConnectionPtr&) { cout << "The Glacier2 session has been destroyed." << endl; }); // diff --git a/cpp/Glacier2/simpleChat/ChatSessionI.cpp b/cpp/Glacier2/simpleChat/ChatSessionI.cpp index 0b6f9f94e..db2f461d2 100644 --- a/cpp/Glacier2/simpleChat/ChatSessionI.cpp +++ b/cpp/Glacier2/simpleChat/ChatSessionI.cpp @@ -46,14 +46,14 @@ void ChatRoom::enter(ChatSessionPrx session, ChatCallbackPrx callback, const Ice::Current& current) { const lock_guard sync(_mutex); - _callbacks.push_back(callback); + _callbacks.emplace_back(std::move(callback)); auto p = _connectionMap.find(current.con); if (p == _connectionMap.end()) { cout << "enter: create new entry in connection map" << endl; - _connectionMap[current.con].push_back(session); + _connectionMap[current.con].emplace_back(std::move(session)); current.con->setCloseCallback( [this](const shared_ptr& con) @@ -68,7 +68,7 @@ ChatRoom::enter(ChatSessionPrx session, ChatCallbackPrx callback, const Ice::Cur else { cout << "enter: add session to existing connection map entry" << endl; - p->second.push_back(session); + p->second.emplace_back(std::move(session)); } } diff --git a/cpp/Glacier2/simpleChat/Client.cpp b/cpp/Glacier2/simpleChat/Client.cpp index 7ff363b25..c5161c957 100644 --- a/cpp/Glacier2/simpleChat/Client.cpp +++ b/cpp/Glacier2/simpleChat/Client.cpp @@ -13,10 +13,10 @@ using namespace Demo; // mutex to prevent intertwined cout output mutex coutMutex; -class ChatCallbackI : public ChatCallback +class ChatCallbackI final : public ChatCallback { public: - virtual void message(string data, const Ice::Current&) override + void message(string data, const Ice::Current&) final { const lock_guard lock(coutMutex); cout << data << endl; @@ -102,7 +102,7 @@ run(const shared_ptr& communicator) const Ice::ConnectionPtr connection = router->ice_getCachedConnection(); assert(connection); connection->setCloseCallback( - [](Ice::ConnectionPtr) + [](const Ice::ConnectionPtr&) { const lock_guard lock(coutMutex); cout << "The Glacier2 session has been destroyed." << endl; diff --git a/cpp/Glacier2/simpleChat/Server.cpp b/cpp/Glacier2/simpleChat/Server.cpp index 788d90d8e..e0b35bbf2 100644 --- a/cpp/Glacier2/simpleChat/Server.cpp +++ b/cpp/Glacier2/simpleChat/Server.cpp @@ -10,10 +10,10 @@ using namespace std; using namespace Demo; -class DummyPermissionsVerifierI : public Glacier2::PermissionsVerifier +class DummyPermissionsVerifierI final : public Glacier2::PermissionsVerifier { public: - virtual bool checkPermissions(string userId, string password, string&, const Ice::Current&) const override + bool checkPermissions(string userId, string password, string&, const Ice::Current&) const final { cout << "verified user `" << userId << "' with password `" << password << "'" << endl; return true; diff --git a/cpp/Ice/async/Client.cpp b/cpp/Ice/async/Client.cpp index 38c75a95f..decf51000 100644 --- a/cpp/Ice/async/Client.cpp +++ b/cpp/Ice/async/Client.cpp @@ -75,7 +75,7 @@ run(const shared_ptr& communicator) hello->sayHelloAsync( 5000, nullptr, - [](exception_ptr e) + [](const exception_ptr& e) { try { diff --git a/cpp/Ice/asyncInvocation/Client.cpp b/cpp/Ice/asyncInvocation/Client.cpp index 94523247e..ed68076ba 100644 --- a/cpp/Ice/asyncInvocation/Client.cpp +++ b/cpp/Ice/asyncInvocation/Client.cpp @@ -125,7 +125,7 @@ run(const shared_ptr& communicator, const string& appName) assert(false); p.set_value(make_tuple(answer, remainder)); }, - [&p](exception_ptr ex) { p.set_exception(ex); }); + [&p](const exception_ptr& ex) { p.set_exception(ex); }); try { auto result = p.get_future().get(); diff --git a/cpp/Ice/bidir/CallbackI.cpp b/cpp/Ice/bidir/CallbackI.cpp index d50120641..abdd32c32 100644 --- a/cpp/Ice/bidir/CallbackI.cpp +++ b/cpp/Ice/bidir/CallbackI.cpp @@ -14,7 +14,7 @@ CallbackSenderI::addClient(optional client, const Ice::Curr { const lock_guard lock(_mutex); cout << "adding client `" << Ice::identityToString(client->ice_getIdentity()) << "'" << endl; - _clients.push_back(client->ice_fixed(current.con)); + _clients.emplace_back(client->ice_fixed(current.con)); } void @@ -74,14 +74,14 @@ CallbackSenderI::invokeCallback() for (const auto& p : _clients) { auto self = shared_from_this(); - p->callbackAsync(num, nullptr, [self, p](exception_ptr eptr) { self->removeClient(p, eptr); }); + p->callbackAsync(num, nullptr, [self, p](const exception_ptr& eptr) { self->removeClient(p, eptr); }); } } } } void -CallbackSenderI::removeClient(const optional& client, exception_ptr eptr) +CallbackSenderI::removeClient(const optional& client, const exception_ptr& eptr) { const lock_guard lock(_mutex); auto p = find(_clients.begin(), _clients.end(), client); diff --git a/cpp/Ice/bidir/CallbackI.h b/cpp/Ice/bidir/CallbackI.h index 6e7f1873c..06c8a3d02 100644 --- a/cpp/Ice/bidir/CallbackI.h +++ b/cpp/Ice/bidir/CallbackI.h @@ -17,7 +17,7 @@ class CallbackSenderI final : public Demo::CallbackSender, public std::enable_sh private: void invokeCallback(); - void removeClient(const std::optional&, std::exception_ptr); + void removeClient(const std::optional&, const std::exception_ptr&); bool _destroy = false; std::vector> _clients; diff --git a/cpp/Ice/interleaved/ThroughputI.cpp b/cpp/Ice/interleaved/ThroughputI.cpp index a251a21f9..f3e4ad351 100644 --- a/cpp/Ice/interleaved/ThroughputI.cpp +++ b/cpp/Ice/interleaved/ThroughputI.cpp @@ -8,7 +8,7 @@ Demo::Throughput::EchoByteSeqMarshaledResult ThroughputI::echoByteSeq(std::pair seq, const Ice::Current& current) { - return EchoByteSeqMarshaledResult(seq, current); + return {seq, current}; } void diff --git a/cpp/Ice/invoke/Client.cpp b/cpp/Ice/invoke/Client.cpp index 92104f280..6e8299229 100644 --- a/cpp/Ice/invoke/Client.cpp +++ b/cpp/Ice/invoke/Client.cpp @@ -194,13 +194,13 @@ run(const shared_ptr& communicator) Ice::OutputStream out(communicator); out.startEncapsulation(); Demo::StructureSeq arr; - arr.push_back(Demo::Structure()); + arr.emplace_back(); arr.back().name = "red"; arr.back().value = Color::red; - arr.push_back(Demo::Structure()); + arr.emplace_back(); arr.back().name = "green"; arr.back().value = Color::green; - arr.push_back(Demo::Structure()); + arr.emplace_back(); arr.back().name = "blue"; arr.back().value = Color::blue; out.write(arr); diff --git a/cpp/Ice/locator/Locator.cpp b/cpp/Ice/locator/Locator.cpp index 84bd37457..033a4f660 100644 --- a/cpp/Ice/locator/Locator.cpp +++ b/cpp/Ice/locator/Locator.cpp @@ -95,7 +95,11 @@ namespace response(_registry->getAdapter(id)); } - optional getRegistry(const Ice::Current&) const final { return _registryPrx; } + [[nodiscard]] + optional getRegistry(const Ice::Current&) const final + { + return _registryPrx; + } private: const shared_ptr _registry; diff --git a/cpp/Ice/mtalk/Client.cpp b/cpp/Ice/mtalk/Client.cpp index f14b224a5..ed89e83d0 100644 --- a/cpp/Ice/mtalk/Client.cpp +++ b/cpp/Ice/mtalk/Client.cpp @@ -106,9 +106,9 @@ class DiscoverTask { public: DiscoverTask(optional d, string n, optional p) - : _discovery(d), - _name(n), - _proxy(p) + : _discovery(std::move(d)), + _name(std::move(n)), + _proxy(std::move(p)) { } @@ -179,7 +179,7 @@ main(int argc, char* argv[]) // and its dtor destroys this communicator. // Ice::CommunicatorHolder ich(argc, argv, "config"); - auto communicator = ich.communicator(); + const auto& communicator = ich.communicator(); // // The communicator initialization removes all Ice-related arguments from argc/argv diff --git a/cpp/Ice/nested/Client.cpp b/cpp/Ice/nested/Client.cpp index b19c2d6a3..de15cff47 100644 --- a/cpp/Ice/nested/Client.cpp +++ b/cpp/Ice/nested/Client.cpp @@ -82,7 +82,7 @@ run(const shared_ptr& communicator) { cout << "enter nesting level or 'x' for exit: "; cin >> s; - int level = atoi(s.c_str()); + int level = stoi(s.c_str()); if (level > 0) { nested->nestedCall(level, self); diff --git a/cpp/Ice/optional/ContactDBI.cpp b/cpp/Ice/optional/ContactDBI.cpp index 89f73f461..02aa6df07 100644 --- a/cpp/Ice/optional/ContactDBI.cpp +++ b/cpp/Ice/optional/ContactDBI.cpp @@ -21,7 +21,7 @@ ContactDBI::addContact( contact->name = name; if (type) { - contact->type = std::move(type); + contact->type = type; } if (number) { @@ -29,7 +29,7 @@ ContactDBI::addContact( } if (dialGroup) { - contact->dialGroup = std::move(dialGroup); + contact->dialGroup = dialGroup; } auto p = _contacts.insert(make_pair(name, contact)); if (!p.second) @@ -51,15 +51,15 @@ ContactDBI::updateContact( { if (type) { - p->second->type = std::move(type); + p->second->type = type; } if (number) { - p->second->number = std::move(number); + p->second->number = number; } if (dialGroup) { - p->second->dialGroup = std::move(dialGroup); + p->second->dialGroup = dialGroup; } } } @@ -72,7 +72,7 @@ ContactDBI::query(string name, const Ice::Current&) { return p->second; } - return 0; + return nullptr; } optional diff --git a/cpp/Ice/plugin/HelloPluginI.cpp b/cpp/Ice/plugin/HelloPluginI.cpp index 401737ed7..40d8cc2a6 100644 --- a/cpp/Ice/plugin/HelloPluginI.cpp +++ b/cpp/Ice/plugin/HelloPluginI.cpp @@ -10,34 +10,34 @@ using namespace std; namespace { - class HelloI : public Demo::Hello + class HelloI final : public Demo::Hello { public: - virtual void sayHello(const Ice::Current& current) override + void sayHello(const Ice::Current& current) final { current.adapter->getCommunicator()->getLogger()->print("Hello World!"); } - virtual void shutdown(const Ice::Current& current) override + void shutdown(const Ice::Current& current) final { current.adapter->getCommunicator()->getLogger()->print("Shutting down..."); current.adapter->getCommunicator()->shutdown(); } }; - class HelloPluginI : public Ice::Plugin + class HelloPluginI final : public Ice::Plugin { public: HelloPluginI(const shared_ptr& communicator) : _communicator(communicator) {} - void initialize() override + void initialize() final { auto adapter = _communicator->createObjectAdapter("Hello"); adapter->add(make_shared(), Ice::stringToIdentity("hello")); adapter->activate(); } - void destroy() override {} + void destroy() final {} private: shared_ptr _communicator; diff --git a/cpp/Ice/plugin/LoggerPluginI.cpp b/cpp/Ice/plugin/LoggerPluginI.cpp index 6234858cf..5e62f7aeb 100644 --- a/cpp/Ice/plugin/LoggerPluginI.cpp +++ b/cpp/Ice/plugin/LoggerPluginI.cpp @@ -11,23 +11,23 @@ using namespace std; namespace { - class LoggerI : public Ice::Logger + class LoggerI final : public Ice::Logger { public: - virtual void print(const string& message) override { cout << "PRINT: " << message << endl; } + void print(const string& message) final { cout << "PRINT: " << message << endl; } - virtual void trace(const string& category, const string& message) override + void trace(const string& category, const string& message) final { cout << "TRACE(" << category << "): " << message << endl; } - virtual void warning(const string& message) override { cout << "WARNING: " << message << endl; } + void warning(const string& message) final { cout << "WARNING: " << message << endl; } - virtual void error(const string& message) override { cout << "ERROR: " << message << endl; } + void error(const string& message) final { cout << "ERROR: " << message << endl; } - virtual string getPrefix() override { return ""; } + string getPrefix() final { return ""; } - virtual shared_ptr cloneWithPrefix(const std::string&) override { return make_shared(); } + shared_ptr cloneWithPrefix(const std::string&) final { return make_shared(); } }; } diff --git a/cpp/Ice/properties/Server.cpp b/cpp/Ice/properties/Server.cpp index deef5b4ee..474ee42d2 100644 --- a/cpp/Ice/properties/Server.cpp +++ b/cpp/Ice/properties/Server.cpp @@ -11,10 +11,10 @@ using namespace std; // // The servant implements the Slice interface Demo::Props // -class PropsI : public Demo::Props +class PropsI final : public Demo::Props { public: - virtual Ice::PropertyDict getChanges(const Ice::Current&) override + Ice::PropertyDict getChanges(const Ice::Current&) final { unique_lock lock(_mutex); @@ -31,7 +31,7 @@ class PropsI : public Demo::Props return _changes; } - virtual void shutdown(const Ice::Current& current) override { current.adapter->getCommunicator()->shutdown(); } + void shutdown(const Ice::Current& current) final { current.adapter->getCommunicator()->shutdown(); } void updated(const Ice::PropertyDict& changes) { diff --git a/cpp/Ice/session/SessionI.cpp b/cpp/Ice/session/SessionI.cpp index da1511f9f..ef2d3fe14 100644 --- a/cpp/Ice/session/SessionI.cpp +++ b/cpp/Ice/session/SessionI.cpp @@ -8,14 +8,14 @@ using namespace std; using namespace Demo; -class HelloI : public Hello +class HelloI final : public Hello { public: HelloI(string name, int id) : _name(std::move(name)), _id(id) {} - virtual ~HelloI() { cout << "Hello object #" << _id << " for session `" << _name << "' destroyed" << endl; } + ~HelloI() final { cout << "Hello object #" << _id << " for session `" << _name << "' destroyed" << endl; } - void sayHello(const Ice::Current&) override + void sayHello(const Ice::Current&) final { cout << "Hello object #" << _id << " for session `" << _name << "' says:\n" << "Hello " << _name << "!" << endl; @@ -41,7 +41,7 @@ SessionI::createHello(const Ice::Current& current) } auto hello = Ice::uncheckedCast(current.adapter->addWithUUID(make_shared(_name, _nextId++))); - _objs.push_back(hello); + _objs.emplace_back(hello); return hello; } diff --git a/cpp/Ice/throughput/ThroughputI.cpp b/cpp/Ice/throughput/ThroughputI.cpp index efcca90fb..38316242e 100644 --- a/cpp/Ice/throughput/ThroughputI.cpp +++ b/cpp/Ice/throughput/ThroughputI.cpp @@ -46,20 +46,20 @@ ThroughputI::recvByteSeq(const Ice::Current& current) Demo::ByteSeq warmupBytesBuf(1); const std::pair ret = std::make_pair(warmupBytesBuf.data(), warmupBytesBuf.data() + warmupBytesBuf.size()); - return RecvByteSeqMarshaledResult(ret, current); + return {ret, current}; } else { const std::pair ret = std::make_pair(_byteSeq.data(), _byteSeq.data() + _byteSeq.size()); - return RecvByteSeqMarshaledResult(ret, current); + return {ret, current}; } } Demo::Throughput::EchoByteSeqMarshaledResult ThroughputI::echoByteSeq(std::pair seq, const Ice::Current& current) { - return EchoByteSeqMarshaledResult(seq, current); + return {seq, current}; } void @@ -72,18 +72,18 @@ ThroughputI::recvStringSeq(const Ice::Current& current) { if (_warmup) { - return RecvStringSeqMarshaledResult(std::vector(1), current); + return {std::vector(1), current}; } else { - return RecvStringSeqMarshaledResult(_stringSeq, current); + return {_stringSeq, current}; } } Demo::Throughput::EchoStringSeqMarshaledResult ThroughputI::echoStringSeq(std::vector seq, const Ice::Current& current) { - return EchoStringSeqMarshaledResult(seq, current); + return {seq, current}; } void diff --git a/cpp/IceGrid/customLocator/Locator.cpp b/cpp/IceGrid/customLocator/Locator.cpp index 63ce2c7ab..c4910eb26 100644 --- a/cpp/IceGrid/customLocator/Locator.cpp +++ b/cpp/IceGrid/customLocator/Locator.cpp @@ -102,7 +102,11 @@ namespace } } - optional getRegistry(const Ice::Current&) const final { return _registry; } + [[nodiscard]] + optional getRegistry(const Ice::Current&) const final + { + return _registry; + } private: const optional _locator; diff --git a/cpp/IceGrid/replication/HelloI.cpp b/cpp/IceGrid/replication/HelloI.cpp index b3e97614f..ed2a613ae 100644 --- a/cpp/IceGrid/replication/HelloI.cpp +++ b/cpp/IceGrid/replication/HelloI.cpp @@ -8,7 +8,7 @@ using namespace std; -HelloI::HelloI(const string& name) : _name(name) {} +HelloI::HelloI(string_view name) : _name(name) {} string HelloI::getGreeting(const Ice::Current&) diff --git a/cpp/IceGrid/replication/HelloI.h b/cpp/IceGrid/replication/HelloI.h index 25df8f07c..3289f1a42 100644 --- a/cpp/IceGrid/replication/HelloI.h +++ b/cpp/IceGrid/replication/HelloI.h @@ -7,13 +7,13 @@ #include -class HelloI : public Demo::Hello +class HelloI final : public Demo::Hello { public: - HelloI(const std::string&); + HelloI(std::string_view); - virtual std::string getGreeting(const Ice::Current&) override; - virtual void shutdown(const Ice::Current&) override; + std::string getGreeting(const Ice::Current&) final; + void shutdown(const Ice::Current&) final; private: const std::string _name; diff --git a/cpp/IceGrid/sessionActivation/HelloI.cpp b/cpp/IceGrid/sessionActivation/HelloI.cpp index da44c0265..941375da7 100644 --- a/cpp/IceGrid/sessionActivation/HelloI.cpp +++ b/cpp/IceGrid/sessionActivation/HelloI.cpp @@ -8,7 +8,7 @@ using namespace std; -HelloI::HelloI(const string& name) : _name(name) {} +HelloI::HelloI(string_view name) : _name(name) {} void HelloI::sayHello(const Ice::Current&) diff --git a/cpp/IceGrid/sessionActivation/HelloI.h b/cpp/IceGrid/sessionActivation/HelloI.h index 7fdbf84b6..cca471ca6 100644 --- a/cpp/IceGrid/sessionActivation/HelloI.h +++ b/cpp/IceGrid/sessionActivation/HelloI.h @@ -5,14 +5,14 @@ #ifndef HELLO_I_H #define HELLO_I_H -#include +#include "Hello.h" -class HelloI : public Demo::Hello +class HelloI final : public Demo::Hello { public: - HelloI(const std::string&); + HelloI(std::string_view); - virtual void sayHello(const Ice::Current&) override; + void sayHello(const Ice::Current&) final; private: const std::string _name; diff --git a/cpp/IceGrid/simple/HelloI.cpp b/cpp/IceGrid/simple/HelloI.cpp index 86349ebcc..bda43a398 100644 --- a/cpp/IceGrid/simple/HelloI.cpp +++ b/cpp/IceGrid/simple/HelloI.cpp @@ -8,7 +8,7 @@ using namespace std; -HelloI::HelloI(const string& name) : _name(name) {} +HelloI::HelloI(string_view name) : _name(name) {} void HelloI::sayHello(const Ice::Current&) diff --git a/cpp/IceGrid/simple/HelloI.h b/cpp/IceGrid/simple/HelloI.h index 7080fe21d..4f27a96db 100644 --- a/cpp/IceGrid/simple/HelloI.h +++ b/cpp/IceGrid/simple/HelloI.h @@ -7,13 +7,13 @@ #include -class HelloI : public Demo::Hello +class HelloI final : public Demo::Hello { public: - HelloI(const std::string&); + HelloI(std::string_view); - virtual void sayHello(const Ice::Current&) override; - virtual void shutdown(const Ice::Current&) override; + void sayHello(const Ice::Current&) final; + void shutdown(const Ice::Current&) final; private: const std::string _name; diff --git a/cpp/IceStorm/clock/Publisher.cpp b/cpp/IceStorm/clock/Publisher.cpp index 7b7846eb1..dbc1bceac 100644 --- a/cpp/IceStorm/clock/Publisher.cpp +++ b/cpp/IceStorm/clock/Publisher.cpp @@ -65,7 +65,7 @@ usage(const string& n) int run(const shared_ptr& communicator, int argc, char* argv[]) { - enum class Option + enum class Option : uint8_t { None, Datagram, diff --git a/cpp/IceStorm/clock/Subscriber.cpp b/cpp/IceStorm/clock/Subscriber.cpp index bf2496c05..6b8cbd1e5 100644 --- a/cpp/IceStorm/clock/Subscriber.cpp +++ b/cpp/IceStorm/clock/Subscriber.cpp @@ -10,10 +10,10 @@ using namespace std; using namespace Demo; -class ClockI : public Clock +class ClockI final : public Clock { public: - virtual void tick(string time, const Ice::Current&) override { cout << time << endl; } + void tick(string time, const Ice::Current&) final { cout << time << endl; } }; int run(const shared_ptr& communicator, int argc, char* argv[]); @@ -69,7 +69,7 @@ run(const shared_ptr& communicator, int argc, char* argv[]) Ice::stringSeqToArgs(args, argc, argv); bool batch = false; - enum class Option + enum class Option : uint8_t { None, Datagram, diff --git a/cpp/IceStorm/replicated/Publisher.cpp b/cpp/IceStorm/replicated/Publisher.cpp index bc9b05188..45630ff2c 100644 --- a/cpp/IceStorm/replicated/Publisher.cpp +++ b/cpp/IceStorm/replicated/Publisher.cpp @@ -65,7 +65,7 @@ usage(const string& n) int run(const shared_ptr& communicator, int argc, char* argv[]) { - enum class Option + enum class Option : uint8_t { None, Datagram, diff --git a/cpp/IceStorm/replicated/Subscriber.cpp b/cpp/IceStorm/replicated/Subscriber.cpp index 59abfbe19..61c61d350 100644 --- a/cpp/IceStorm/replicated/Subscriber.cpp +++ b/cpp/IceStorm/replicated/Subscriber.cpp @@ -69,7 +69,7 @@ run(const shared_ptr& communicator, int argc, char* argv[]) Ice::stringSeqToArgs(args, argc, argv); bool batch = false; - enum class Option + enum class Option : uint8_t { None, Datagram, diff --git a/cpp/IceStorm/replicated2/Publisher.cpp b/cpp/IceStorm/replicated2/Publisher.cpp index bc9b05188..45630ff2c 100644 --- a/cpp/IceStorm/replicated2/Publisher.cpp +++ b/cpp/IceStorm/replicated2/Publisher.cpp @@ -65,7 +65,7 @@ usage(const string& n) int run(const shared_ptr& communicator, int argc, char* argv[]) { - enum class Option + enum class Option : uint8_t { None, Datagram, diff --git a/cpp/IceStorm/replicated2/Subscriber.cpp b/cpp/IceStorm/replicated2/Subscriber.cpp index 42f287512..44559436b 100644 --- a/cpp/IceStorm/replicated2/Subscriber.cpp +++ b/cpp/IceStorm/replicated2/Subscriber.cpp @@ -10,10 +10,10 @@ using namespace std; using namespace Demo; -class ClockI : public Clock +class ClockI final : public Clock { public: - virtual void tick(string time, const Ice::Current&) override { cout << time << endl; } + void tick(string time, const Ice::Current&) final { cout << time << endl; } }; int run(const shared_ptr& communicator, int argc, char* argv[]); @@ -69,7 +69,7 @@ run(const shared_ptr& communicator, int argc, char* argv[]) Ice::stringSeqToArgs(args, argc, argv); bool batch = false; - enum class Option + enum class Option : uint8_t { None, Datagram, diff --git a/cpp/Manual/printer/Server.cpp b/cpp/Manual/printer/Server.cpp index 0dcf787dc..d67f35c7a 100644 --- a/cpp/Manual/printer/Server.cpp +++ b/cpp/Manual/printer/Server.cpp @@ -9,10 +9,10 @@ using namespace std; using namespace Demo; -class PrinterI : public Printer +class PrinterI final : public Printer { public: - virtual void printString(string s, const Ice::Current&) override; + void printString(string s, const Ice::Current&) final; }; void