From 92d35e54c7de6bbe44ff6c7c52cc0765b3f78258 Mon Sep 17 00:00:00 2001 From: seelabs Date: Tue, 16 Nov 2021 22:31:34 -0500 Subject: [PATCH] Switch from C++17 to C++20 --- CMakeLists.txt | 2 +- src/ripple/app/consensus/RCLConsensus.cpp | 4 +- src/ripple/app/paths/impl/BookStep.cpp | 8 +-- src/ripple/basics/TaggedCache.h | 2 +- src/ripple/beast/utility/PropertyStream.h | 12 ---- .../utility/src/beast_PropertyStream.cpp | 36 ----------- src/ripple/consensus/Validations.h | 4 +- src/ripple/ledger/OpenView.h | 2 +- src/ripple/ledger/detail/RawStateTable.h | 2 +- .../nodestore/backend/RocksDBFactory.cpp | 5 +- src/ripple/overlay/Slot.h | 39 +++++------- src/ripple/overlay/impl/PeerImp.cpp | 2 +- src/ripple/protocol/Feature.h | 1 - src/ripple/protocol/Serializer.h | 8 +-- src/ripple/rpc/impl/ShardArchiveHandler.cpp | 63 ++++++++++--------- src/test/app/Path_test.cpp | 2 +- src/test/core/Coroutine_test.cpp | 2 +- src/test/csf/Peer.h | 2 +- 18 files changed, 75 insertions(+), 121 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c0c0fff944..d3b494c103 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ endif () project (rippled) set(CMAKE_CXX_EXTENSIONS OFF) -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) # make GIT_COMMIT_HASH define available to all sources diff --git a/src/ripple/app/consensus/RCLConsensus.cpp b/src/ripple/app/consensus/RCLConsensus.cpp index 79d41581ae..a4a4e0989a 100644 --- a/src/ripple/app/consensus/RCLConsensus.cpp +++ b/src/ripple/app/consensus/RCLConsensus.cpp @@ -421,7 +421,9 @@ RCLConsensus::Adaptor::onAccept( Json::Value&& consensusJson) { app_.getJobQueue().addJob( - jtACCEPT, "acceptLedger", [=, cj = std::move(consensusJson)]() mutable { + jtACCEPT, + "acceptLedger", + [=, this, cj = std::move(consensusJson)]() mutable { // Note that no lock is held or acquired during this job. // This is because generic Consensus guarantees that once a ledger // is accepted, the consensus results and capture by reference state diff --git a/src/ripple/app/paths/impl/BookStep.cpp b/src/ripple/app/paths/impl/BookStep.cpp index a80ee13f8a..a6b2c59611 100644 --- a/src/ripple/app/paths/impl/BookStep.cpp +++ b/src/ripple/app/paths/impl/BookStep.cpp @@ -1125,10 +1125,10 @@ bookStepEqual(Step const& step, ripple::Book const& book) bool const inXRP = isXRP(book.in.currency); bool const outXRP = isXRP(book.out.currency); if (inXRP && outXRP) - return equalHelper< - XRPAmount, - XRPAmount, - BookPaymentStep>(step, book); + { + assert(0); + return false; // no such thing as xrp/xrp book step + } if (inXRP && !outXRP) return equalHelper< XRPAmount, diff --git a/src/ripple/basics/TaggedCache.h b/src/ripple/basics/TaggedCache.h index 548d21dc78..d9a1b542ed 100644 --- a/src/ripple/basics/TaggedCache.h +++ b/src/ripple/basics/TaggedCache.h @@ -684,7 +684,7 @@ private: { // strong, expired ++cacheRemovals; - if (cit->second.ptr.unique()) + if (cit->second.ptr.use_count() == 1) { stuffToSweep.push_back(cit->second.ptr); ++mapRemovals; diff --git a/src/ripple/beast/utility/PropertyStream.h b/src/ripple/beast/utility/PropertyStream.h index bfedb39ecd..dbcc8a2d79 100644 --- a/src/ripple/beast/utility/PropertyStream.h +++ b/src/ripple/beast/utility/PropertyStream.h @@ -77,12 +77,6 @@ protected: add(std::string const& key, signed char value); virtual void add(std::string const& key, unsigned char value); - virtual void - add(std::string const& key, wchar_t value); -#if 0 - virtual void add (std::string const& key, char16_t value); - virtual void add (std::string const& key, char32_t value); -#endif virtual void add(std::string const& key, short value); virtual void @@ -139,12 +133,6 @@ protected: add(signed char value); virtual void add(unsigned char value); - virtual void - add(wchar_t value); -#if 0 - virtual void add (char16_t value); - virtual void add (char32_t value); -#endif virtual void add(short value); virtual void diff --git a/src/ripple/beast/utility/src/beast_PropertyStream.cpp b/src/ripple/beast/utility/src/beast_PropertyStream.cpp index 70c5ab9a80..ecd707e955 100644 --- a/src/ripple/beast/utility/src/beast_PropertyStream.cpp +++ b/src/ripple/beast/utility/src/beast_PropertyStream.cpp @@ -414,24 +414,6 @@ PropertyStream::add(std::string const& key, unsigned char value) lexical_add(key, value); } -void -PropertyStream::add(std::string const& key, wchar_t value) -{ - lexical_add(key, value); -} - -#if 0 -void PropertyStream::add (std::string const& key, char16_t value) -{ - lexical_add (key, value); -} - -void PropertyStream::add (std::string const& key, char32_t value) -{ - lexical_add (key, value); -} -#endif - void PropertyStream::add(std::string const& key, short value) { @@ -525,24 +507,6 @@ PropertyStream::add(unsigned char value) lexical_add(value); } -void -PropertyStream::add(wchar_t value) -{ - lexical_add(value); -} - -#if 0 -void PropertyStream::add (char16_t value) -{ - lexical_add (value); -} - -void PropertyStream::add (char32_t value) -{ - lexical_add (value); -} -#endif - void PropertyStream::add(short value) { diff --git a/src/ripple/consensus/Validations.h b/src/ripple/consensus/Validations.h index 9200ac883c..46bf4322a5 100644 --- a/src/ripple/consensus/Validations.h +++ b/src/ripple/consensus/Validations.h @@ -27,8 +27,10 @@ #include #include #include + #include #include +#include #include #include @@ -294,7 +296,7 @@ class Validations using NodeKey = typename Validation::NodeKey; using WrappedValidationType = std::decay_t< - std::result_of_t>; + std::invoke_result_t>; // Manages concurrent access to members mutable Mutex mutex_; diff --git a/src/ripple/ledger/OpenView.h b/src/ripple/ledger/OpenView.h index 8467e4abcc..98b783e3a4 100644 --- a/src/ripple/ledger/OpenView.h +++ b/src/ripple/ledger/OpenView.h @@ -77,7 +77,7 @@ private: }; // List of tx, key order - // Use the boost pmr functionality instead of the c++-17 standard pmr + // Use boost::pmr functionality instead of std::pmr // functions b/c clang does not support pmr yet (as-of 9/2020) using txs_map = std::map< key_type, diff --git a/src/ripple/ledger/detail/RawStateTable.h b/src/ripple/ledger/detail/RawStateTable.h index 2bee9e2a94..2bb38dc49d 100644 --- a/src/ripple/ledger/detail/RawStateTable.h +++ b/src/ripple/ledger/detail/RawStateTable.h @@ -119,7 +119,7 @@ private: } }; - // Use the boost pmr functionality instead of the c++-17 standard pmr + // Use boost::pmr functionality instead of the std::pmr // functions b/c clang does not support pmr yet (as-of 9/2020) using items_t = std::map< key_type, diff --git a/src/ripple/nodestore/backend/RocksDBFactory.cpp b/src/ripple/nodestore/backend/RocksDBFactory.cpp index e17dc55de7..1a9e529e10 100644 --- a/src/ripple/nodestore/backend/RocksDBFactory.cpp +++ b/src/ripple/nodestore/backend/RocksDBFactory.cpp @@ -23,6 +23,7 @@ #include #include +#include #include #include // VFALCO Bad dependency #include @@ -30,6 +31,7 @@ #include #include #include + #include #include @@ -310,7 +312,8 @@ public: } else { - status = Status(customCode + getStatus.code()); + status = + Status(customCode + unsafe_cast(getStatus.code())); JLOG(m_journal.error()) << getStatus.ToString(); } diff --git a/src/ripple/overlay/Slot.h b/src/ripple/overlay/Slot.h index b7a2129ed8..1197eff56e 100644 --- a/src/ripple/overlay/Slot.h +++ b/src/ripple/overlay/Slot.h @@ -494,16 +494,11 @@ template std::set Slot::getSelected() const { - std::set init; - return std::accumulate( - peers_.begin(), peers_.end(), init, [](auto& init, auto const& it) { - if (it.second.state == PeerState::Selected) - { - init.insert(it.first); - return init; - } - return init; - }); + std::set r; + for (auto const& [id, info] : peers_) + if (info.state == PeerState::Selected) + r.insert(id); + return r; } template @@ -513,20 +508,20 @@ std::unordered_map< Slot::getPeers() const { using namespace std::chrono; - auto init = std::unordered_map< + auto r = std::unordered_map< id_t, std::tuple>(); - return std::accumulate( - peers_.begin(), peers_.end(), init, [](auto& init, auto const& it) { - init.emplace(std::make_pair( - it.first, - std::move(std::make_tuple( - it.second.state, - it.second.count, - epoch(it.second.expire).count(), - epoch(it.second.lastMessage).count())))); - return init; - }); + + for (auto const& [id, info] : peers_) + r.emplace(std::make_pair( + id, + std::move(std::make_tuple( + info.state, + info.count, + epoch(info.expire).count(), + epoch(info.lastMessage).count())))); + + return r; } /** Slots is a container for validator's Slot and handles Slot update diff --git a/src/ripple/overlay/impl/PeerImp.cpp b/src/ripple/overlay/impl/PeerImp.cpp index 60870c90a1..5962ab0dfc 100644 --- a/src/ripple/overlay/impl/PeerImp.cpp +++ b/src/ripple/overlay/impl/PeerImp.cpp @@ -2119,7 +2119,7 @@ PeerImp::onMessage(std::shared_ptr const& m) m->ledgerseq(), app_.getLedgerMaster().getValidLedgerIndex()); } - app_.getOPs().pubPeerStatus([=]() -> Json::Value { + app_.getOPs().pubPeerStatus([=, this]() -> Json::Value { Json::Value j = Json::objectValue; if (m->has_newstatus()) diff --git a/src/ripple/protocol/Feature.h b/src/ripple/protocol/Feature.h index f0d0c8efbb..b46e4d588e 100644 --- a/src/ripple/protocol/Feature.h +++ b/src/ripple/protocol/Feature.h @@ -126,7 +126,6 @@ class FeatureBitset : private std::bitset public: using base::bitset; using base::operator==; - using base::operator!=; using base::all; using base::any; diff --git a/src/ripple/protocol/Serializer.h b/src/ripple/protocol/Serializer.h index 37058f5622..7c3ccf9580 100644 --- a/src/ripple/protocol/Serializer.h +++ b/src/ripple/protocol/Serializer.h @@ -251,22 +251,22 @@ public: } bool - operator==(Blob const& v) + operator==(Blob const& v) const { return v == mData; } bool - operator!=(Blob const& v) + operator!=(Blob const& v) const { return v != mData; } bool - operator==(const Serializer& v) + operator==(const Serializer& v) const { return v.mData == mData; } bool - operator!=(const Serializer& v) + operator!=(const Serializer& v) const { return v.mData != mData; } diff --git a/src/ripple/rpc/impl/ShardArchiveHandler.cpp b/src/ripple/rpc/impl/ShardArchiveHandler.cpp index 5e5635475e..2284780c2b 100644 --- a/src/ripple/rpc/impl/ShardArchiveHandler.cpp +++ b/src/ripple/rpc/impl/ShardArchiveHandler.cpp @@ -416,41 +416,42 @@ ShardArchiveHandler::complete(path dstPath) } // Make lambdas mutable captured vars can be moved from - auto wrapper = jobCounter_.wrap([=, - dstPath = std::move(dstPath)]() mutable { - if (stopping_) - return; + auto wrapper = + jobCounter_.wrap([=, this, dstPath = std::move(dstPath)]() mutable { + if (stopping_) + return; - // If not synced then defer and retry - auto const mode{app_.getOPs().getOperatingMode()}; - if (mode != OperatingMode::FULL) - { - std::lock_guard lock(m_); - timer_.expires_from_now(static_cast( - (static_cast(OperatingMode::FULL) - - static_cast(mode)) * - 10)); + // If not synced then defer and retry + auto const mode{app_.getOPs().getOperatingMode()}; + if (mode != OperatingMode::FULL) + { + std::lock_guard lock(m_); + timer_.expires_from_now(static_cast( + (static_cast(OperatingMode::FULL) - + static_cast(mode)) * + 10)); - auto wrapper = timerCounter_.wrap( - [=, dstPath = std::move(dstPath)]( - boost::system::error_code const& ec) mutable { - if (ec != boost::asio::error::operation_aborted) - complete(std::move(dstPath)); - }); + auto wrapper = timerCounter_.wrap( + [=, this, dstPath = std::move(dstPath)]( + boost::system::error_code const& ec) mutable { + if (ec != boost::asio::error::operation_aborted) + complete(std::move(dstPath)); + }); - if (!wrapper) - onClosureFailed( - "failed to wrap closure for operating mode timer", lock); + if (!wrapper) + onClosureFailed( + "failed to wrap closure for operating mode timer", + lock); + else + timer_.async_wait(*wrapper); + } else - timer_.async_wait(*wrapper); - } - else - { - process(dstPath); - std::lock_guard lock(m_); - removeAndProceed(lock); - } - }); + { + process(dstPath); + std::lock_guard lock(m_); + removeAndProceed(lock); + } + }); if (!wrapper) { diff --git a/src/test/app/Path_test.cpp b/src/test/app/Path_test.cpp index 05d23e8297..ef290393da 100644 --- a/src/test/app/Path_test.cpp +++ b/src/test/app/Path_test.cpp @@ -203,7 +203,7 @@ public: wait_for(std::chrono::duration const& rel_time) { std::unique_lock lk(mutex_); - auto b = cv_.wait_for(lk, rel_time, [=] { return signaled_; }); + auto b = cv_.wait_for(lk, rel_time, [this] { return signaled_; }); signaled_ = false; return b; } diff --git a/src/test/core/Coroutine_test.cpp b/src/test/core/Coroutine_test.cpp index 8937255a75..6d1e5e3330 100644 --- a/src/test/core/Coroutine_test.cpp +++ b/src/test/core/Coroutine_test.cpp @@ -44,7 +44,7 @@ public: wait_for(std::chrono::duration const& rel_time) { std::unique_lock lk(mutex_); - auto b = cv_.wait_for(lk, rel_time, [=] { return signaled_; }); + auto b = cv_.wait_for(lk, rel_time, [this] { return signaled_; }); signaled_ = false; return b; } diff --git a/src/test/csf/Peer.h b/src/test/csf/Peer.h index 3a61b853c2..6d3008f734 100644 --- a/src/test/csf/Peer.h +++ b/src/test/csf/Peer.h @@ -538,7 +538,7 @@ struct Peer ConsensusMode const& mode, Json::Value&& consensusJson) { - schedule(delays.ledgerAccept, [=]() { + schedule(delays.ledgerAccept, [=, this]() { const bool proposing = mode == ConsensusMode::proposing; const bool consensusFail = result.state == ConsensusState::MovedOn;