diff --git a/.clang-tidy b/.clang-tidy index 3bad686a11..a79b565e59 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -66,29 +66,9 @@ Checks: "-*, modernize-*, -modernize-avoid-c-arrays, -modernize-avoid-c-style-cast, - -modernize-avoid-setjmp-longjmp, - -modernize-avoid-variadic-functions, - -modernize-deprecated-ios-base-aliases, - -modernize-loop-convert, - -modernize-macro-to-enum, - -modernize-min-max-use-initializer-list, - -modernize-raw-string-literal, - -modernize-redundant-void-arg, - -modernize-replace-auto-ptr, - -modernize-replace-disallow-copy-and-assign-macro, - -modernize-replace-random-shuffle, -modernize-return-braced-init-list, - -modernize-shrink-to-fit, - -modernize-use-bool-literals, - -modernize-use-default-member-init, -modernize-use-integer-sign-comparison, - -modernize-use-noexcept, - -modernize-use-nullptr, - -modernize-use-std-format, - -modernize-use-std-print, -modernize-use-trailing-return-type, - -modernize-use-transparent-functors, - -modernize-use-uncaught-exceptions, performance-*, -performance-avoid-endl, diff --git a/include/xrpl/basics/comparators.h b/include/xrpl/basics/comparators.h deleted file mode 100644 index 0e21d38d6b..0000000000 --- a/include/xrpl/basics/comparators.h +++ /dev/null @@ -1,54 +0,0 @@ -#pragma once - -#include - -namespace xrpl { - -#ifdef _MSC_VER - -/* - * MSVC 2019 version 16.9.0 added [[nodiscard]] to the std comparison - * operator() functions. boost::bimap checks that the comparator is a - * BinaryFunction, in part by calling the function and ignoring the value. - * These two things don't play well together. These wrapper classes simply - * strip [[nodiscard]] from operator() for use in boost::bimap. - * - * See also: - * https://www.boost.org/doc/libs/1_75_0/libs/bimap/doc/html/boost_bimap/the_tutorial/controlling_collection_types.html - */ - -template -struct less -{ - using result_type = bool; - - constexpr bool - operator()(T const& left, T const& right) const - { - return std::less()(left, right); - } -}; - -template -struct equal_to -{ - using result_type = bool; - - constexpr bool - operator()(T const& left, T const& right) const - { - return std::equal_to()(left, right); - } -}; - -#else - -template -using less = std::less; - -template -using equal_to = std::equal_to; - -#endif - -} // namespace xrpl diff --git a/include/xrpl/beast/hash/hash_append.h b/include/xrpl/beast/hash/hash_append.h index da499dc612..3592ffbfe8 100644 --- a/include/xrpl/beast/hash/hash_append.h +++ b/include/xrpl/beast/hash/hash_append.h @@ -392,36 +392,12 @@ hash_append(Hasher& h, boost::container::flat_set const& v) } // tuple -namespace detail { - -inline void -forEachItem(...) noexcept -{ -} - -template -inline int -hashOne(Hasher& h, T const& t) noexcept -{ - hash_append(h, t); - return 0; -} - -template -inline void -tuple_hash(Hasher& h, std::tuple const& t, std::index_sequence) noexcept -{ - for_each_item(hash_one(h, std::get(t))...); -} - -} // namespace detail - template inline void hash_append(Hasher& h, std::tuple const& t) noexcept requires(!IsContiguouslyHashable, Hasher>::value) { - detail::tuple_hash(h, t, std::index_sequence_for{}); + std::apply([&h](auto const&... item) { (hash_append(h, item), ...); }, t); } // shared_ptr diff --git a/include/xrpl/core/HashRouter.h b/include/xrpl/core/HashRouter.h index ef8f24d43c..dad1afb405 100644 --- a/include/xrpl/core/HashRouter.h +++ b/include/xrpl/core/HashRouter.h @@ -127,7 +127,7 @@ private: } [[nodiscard]] HashRouterFlags - getFlags(void) const + getFlags() const { return flags_; } diff --git a/include/xrpl/json/json_reader.h b/include/xrpl/json/json_reader.h index c1535bfb55..d1e4ada579 100644 --- a/include/xrpl/json/json_reader.h +++ b/include/xrpl/json/json_reader.h @@ -154,7 +154,7 @@ private: Location end, unsigned int& unicode); bool - addError(std::string const& message, Token& token, Location extra = 0); + addError(std::string const& message, Token& token, Location extra = nullptr); bool recoverFromError(TokenType skipUntilToken); bool diff --git a/include/xrpl/ledger/OpenView.h b/include/xrpl/ledger/OpenView.h index de81787906..875909715c 100644 --- a/include/xrpl/ledger/OpenView.h +++ b/include/xrpl/ledger/OpenView.h @@ -82,7 +82,7 @@ private: using txs_map = std::map< key_type, TxData, - std::less, + std::less<>, boost::container::pmr::polymorphic_allocator>>; // monotonic_resource_ must outlive `items_`. Make a pointer so it may be diff --git a/include/xrpl/ledger/detail/RawStateTable.h b/include/xrpl/ledger/detail/RawStateTable.h index cfa528d355..2e36a42eaf 100644 --- a/include/xrpl/ledger/detail/RawStateTable.h +++ b/include/xrpl/ledger/detail/RawStateTable.h @@ -105,7 +105,7 @@ private: using items_t = std::map< key_type, SleAction, - std::less, + std::less<>, boost::container::pmr::polymorphic_allocator>>; // monotonic_resource_ must outlive `items_`. Make a pointer so it may be // easily moved. diff --git a/include/xrpl/resource/detail/Logic.h b/include/xrpl/resource/detail/Logic.h index 6b1c5e7397..78cd0ac36c 100644 --- a/include/xrpl/resource/detail/Logic.h +++ b/include/xrpl/resource/detail/Logic.h @@ -351,10 +351,9 @@ public: Import& import(iter->second); if (iter->second.whenExpires <= elapsed) { - for (auto itemIter(import.items.begin()); itemIter != import.items.end(); - ++itemIter) + for (auto& item : import.items) { - itemIter->consumer.entry().remoteBalance -= itemIter->balance; + item.consumer.entry().remoteBalance -= item.balance; } iter = importTable_.erase(iter); diff --git a/include/xrpl/shamap/FullBelowCache.h b/include/xrpl/shamap/FullBelowCache.h index dc597278df..b6d1142eb4 100644 --- a/include/xrpl/shamap/FullBelowCache.h +++ b/include/xrpl/shamap/FullBelowCache.h @@ -103,7 +103,7 @@ public: /** generation determines whether cached entry is valid */ std::uint32_t - getGeneration(void) const + getGeneration() const { return gen_; } diff --git a/src/libxrpl/json/json_reader.cpp b/src/libxrpl/json/json_reader.cpp index 45e448c480..a12ec7b565 100644 --- a/src/libxrpl/json/json_reader.cpp +++ b/src/libxrpl/json/json_reader.cpp @@ -86,8 +86,8 @@ Reader::parse(char const* beginDoc, char const* endDoc, Value& root) begin_ = beginDoc; end_ = endDoc; current_ = begin_; - lastValueEnd_ = 0; - lastValue_ = 0; + lastValueEnd_ = nullptr; + lastValue_ = nullptr; errors_.clear(); while (!nodes_.empty()) @@ -908,9 +908,8 @@ Reader::getFormattedErrorMessages() const { std::string formattedMessage; - for (auto itError = errors_.begin(); itError != errors_.end(); ++itError) + for (auto const& error : errors_) { - ErrorInfo const& error = *itError; formattedMessage += "* " + getLocationLineAndColumn(error.token.start) + "\n"; formattedMessage += " " + error.message + "\n"; diff --git a/src/libxrpl/json/json_value.cpp b/src/libxrpl/json/json_value.cpp index 7218b8c6cf..c679e30e16 100644 --- a/src/libxrpl/json/json_value.cpp +++ b/src/libxrpl/json/json_value.cpp @@ -90,7 +90,7 @@ static struct DummyValueAllocatorInitializer // Notes: index_ indicates if the string was allocated when // a string is stored. -Value::CZString::CZString(int index) : cstr_(0), index_(index) +Value::CZString::CZString(int index) : cstr_(nullptr), index_(index) { } @@ -103,7 +103,8 @@ Value::CZString::CZString(char const* cstr, DuplicationPolicy allocate) Value::CZString::CZString(CZString const& other) : cstr_( - other.index_ != static_cast(DuplicationPolicy::NoDuplication) && other.cstr_ != 0 + other.index_ != static_cast(DuplicationPolicy::NoDuplication) && + other.cstr_ != nullptr ? valueAllocator()->makeMemberName(other.cstr_) : other.cstr_) , index_([&]() -> int { @@ -187,7 +188,7 @@ Value::Value(ValueType type) : type_(type) break; case ValueType::String: - value_.stringVal = 0; + value_.stringVal = nullptr; break; case ValueType::Array: @@ -268,7 +269,7 @@ Value::Value(Value const& other) : type_(other.type_) } else { - value_.stringVal = 0; + value_.stringVal = nullptr; } break; @@ -405,7 +406,7 @@ operator<(Value const& x, Value const& y) return static_cast(x.value_.boolVal) < static_cast(y.value_.boolVal); case ValueType::String: - return (x.value_.stringVal == 0 && (y.value_.stringVal != nullptr)) || + return (x.value_.stringVal == nullptr && (y.value_.stringVal != nullptr)) || ((y.value_.stringVal != nullptr) && (x.value_.stringVal != nullptr) && strcmp(x.value_.stringVal, y.value_.stringVal) < 0); diff --git a/src/libxrpl/net/HTTPClient.cpp b/src/libxrpl/net/HTTPClient.cpp index 7294633964..5edd8b5b47 100644 --- a/src/libxrpl/net/HTTPClient.cpp +++ b/src/libxrpl/net/HTTPClient.cpp @@ -370,10 +370,10 @@ public: {std::istreambuf_iterator(&header_)}, std::istreambuf_iterator()}; JLOG(j_.trace()) << "Header: \"" << strHeader << "\""; - static boost::regex const kReStatus{"\\`HTTP/1\\S+ (\\d{3}) .*\\'"}; // HTTP/1.1 200 OK + static boost::regex const kReStatus{R"(\`HTTP/1\S+ (\d{3}) .*\')"}; // HTTP/1.1 200 OK static boost::regex const kReSize{ - "\\`.*\\r\\nContent-Length:\\s+([0-9]+).*\\'", boost::regex::icase}; - static boost::regex const kReBody{"\\`.*\\r\\n\\r\\n(.*)\\'"}; + R"(\`.*\r\nContent-Length:\s+([0-9]+).*\')", boost::regex::icase}; + static boost::regex const kReBody{R"(\`.*\r\n\r\n(.*)\')"}; boost::smatch smMatch; // Match status code. diff --git a/src/libxrpl/protocol/PublicKey.cpp b/src/libxrpl/protocol/PublicKey.cpp index c6e6c1d324..97948fcae3 100644 --- a/src/libxrpl/protocol/PublicKey.cpp +++ b/src/libxrpl/protocol/PublicKey.cpp @@ -87,11 +87,11 @@ sliceToHex(Slice const& slice) s.reserve(2 * (slice.size() + 1)); s = "0x"; } - for (int i = 0; i < slice.size(); ++i) + for (std::uint8_t const byte : slice) { static constexpr char kHex[] = "0123456789ABCDEF"; - s += kHex[((slice[i] & 0xf0) >> 4)]; - s += kHex[((slice[i] & 0x0f) >> 0)]; + s += kHex[((byte & 0xf0) >> 4)]; + s += kHex[((byte & 0x0f) >> 0)]; } return s; } diff --git a/src/libxrpl/protocol/STObject.cpp b/src/libxrpl/protocol/STObject.cpp index ea8553dc4f..869700baed 100644 --- a/src/libxrpl/protocol/STObject.cpp +++ b/src/libxrpl/protocol/STObject.cpp @@ -502,7 +502,7 @@ STObject::isFlag(std::uint32_t f) const } std::uint32_t -STObject::getFlags(void) const +STObject::getFlags() const { auto const* t = dynamic_cast(peekAtPField(sfFlags)); diff --git a/src/libxrpl/protocol/tokens.cpp b/src/libxrpl/protocol/tokens.cpp index 6716b1185f..21984c67e7 100644 --- a/src/libxrpl/protocol/tokens.cpp +++ b/src/libxrpl/protocol/tokens.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -265,17 +266,17 @@ decodeBase58(std::string const& s) // Allocate enough space in big-endian base256 representation. // log(58) / log(256), rounded up. - std::vector b256((remain * 733 / 1000) + 1); + std::vector b256((remain * 733 / 1000) + 1); while (remain > 0) { auto carry = kAlphabetReverse[*psz]; if (carry == -1) return {}; // Apply "b256 = b256 * 58 + carry". - for (auto iter = b256.rbegin(); iter != b256.rend(); ++iter) + for (std::uint8_t& byte : std::views::reverse(b256)) { - carry += 58 * *iter; - *iter = carry % 256; + carry += 58 * byte; + byte = carry % 256; carry /= 256; } XRPL_ASSERT(carry == 0, "xrpl::b58_ref::detail::decodeBase58 : zero carry"); @@ -283,7 +284,7 @@ decodeBase58(std::string const& s) --remain; } // Skip leading zeroes in b256. - auto iter = std::ranges::find_if(b256, [](unsigned char c) { return c != 0; }); + auto iter = std::ranges::find_if(b256, [](std::uint8_t c) { return c != 0; }); std::string result; result.reserve(zeroes + (b256.end() - iter)); result.assign(zeroes, 0x00); diff --git a/src/test/app/AMMMPT_test.cpp b/src/test/app/AMMMPT_test.cpp index c68270591a..4877406ca1 100644 --- a/src/test/app/AMMMPT_test.cpp +++ b/src/test/app/AMMMPT_test.cpp @@ -3482,8 +3482,8 @@ private: // The vote is not added to the slots ammAlice.vote(carol_, 1'000); auto const info = ammAlice.ammRpcInfo()[jss::amm][jss::vote_slots]; - for (auto i = 0; i < info.size(); ++i) - BEAST_EXPECT(info[i][jss::account] != carol_.human()); + for (auto const& entry : info) + BEAST_EXPECT(entry[jss::account] != carol_.human()); // But the slots are refreshed and the fee is changed BEAST_EXPECT(ammAlice.expectTradingFee(82)); } @@ -6270,7 +6270,7 @@ private: auto const info = env.rpc( "json", "account_info", - std::string("{\"account\": \"" + to_string(amm.ammAccount()) + "\"}")); + std::string(R"({"account": ")" + to_string(amm.ammAccount()) + "\"}")); try { BEAST_EXPECT( diff --git a/src/test/app/AMM_test.cpp b/src/test/app/AMM_test.cpp index d4b6ba5429..f19743026c 100644 --- a/src/test/app/AMM_test.cpp +++ b/src/test/app/AMM_test.cpp @@ -2463,8 +2463,8 @@ private: // The vote is not added to the slots ammAlice.vote(carol_, 1'000); auto const info = ammAlice.ammRpcInfo()[jss::amm][jss::vote_slots]; - for (std::uint32_t i = 0; i < info.size(); ++i) - BEAST_EXPECT(info[i][jss::account] != carol_.human()); + for (auto const& entry : info) + BEAST_EXPECT(entry[jss::account] != carol_.human()); // But the slots are refreshed and the fee is changed BEAST_EXPECT(ammAlice.expectTradingFee(82)); }); @@ -4436,7 +4436,7 @@ private: auto const info = env.rpc( "json", "account_info", - std::string("{\"account\": \"" + to_string(ammAlice.ammAccount()) + "\"}")); + std::string(R"({"account": ")" + to_string(ammAlice.ammAccount()) + "\"}")); auto const flags = info[jss::result][jss::account_data][jss::Flags].asUInt(); BEAST_EXPECT(flags == (lsfDisableMaster | lsfDefaultRipple | lsfDepositAuth)); }); @@ -5265,7 +5265,7 @@ private: auto const info = env.rpc( "json", "account_info", - std::string("{\"account\": \"" + to_string(amm.ammAccount()) + "\"}")); + std::string(R"({"account": ")" + to_string(amm.ammAccount()) + "\"}")); try { BEAST_EXPECT( diff --git a/src/test/app/PayChan_test.cpp b/src/test/app/PayChan_test.cpp index f1a9506e0c..5068472135 100644 --- a/src/test/app/PayChan_test.cpp +++ b/src/test/app/PayChan_test.cpp @@ -1323,10 +1323,10 @@ struct PayChan_test : public beast::unit_test::Suite auto sliceToHex = [](Slice const& slice) { std::string s; s.reserve(2 * slice.size()); - for (int i = 0; i < slice.size(); ++i) + for (std::uint8_t const byte : slice) { - s += "0123456789ABCDEF"[((slice[i] & 0xf0) >> 4)]; - s += "0123456789ABCDEF"[((slice[i] & 0x0f) >> 0)]; + s += "0123456789ABCDEF"[((byte & 0xf0) >> 4)]; + s += "0123456789ABCDEF"[((byte & 0x0f) >> 0)]; } return s; }; diff --git a/src/test/app/PermissionedDomains_test.cpp b/src/test/app/PermissionedDomains_test.cpp index 2cffc18682..784c2b4f56 100644 --- a/src/test/app/PermissionedDomains_test.cpp +++ b/src/test/app/PermissionedDomains_test.cpp @@ -289,8 +289,8 @@ class PermissionedDomains_test : public beast::unit_test::Suite for (auto const& c : alice) human2Acc.emplace(c.human(), c); - for (int i = 0; i < accNum; ++i) - env.fund(XRP(1000), alice[i]); + for (auto const& account : alice) + env.fund(XRP(1000), account); // Create new from existing account with a single credential. pdomain::Credentials const credentials1{{.issuer = alice[2], .credType = "credential1"}}; diff --git a/src/test/app/ValidatorList_test.cpp b/src/test/app/ValidatorList_test.cpp index d71554f714..8077c21863 100644 --- a/src/test/app/ValidatorList_test.cpp +++ b/src/test/app/ValidatorList_test.cpp @@ -146,8 +146,8 @@ private: for (auto const& val : validators) { - data += "{\"validation_public_key\":\"" + strHex(val.masterPublic) + - "\",\"manifest\":\"" + val.manifest + "\"},"; + data += R"({"validation_public_key":")" + strHex(val.masterPublic) + + R"(","manifest":")" + val.manifest + "\"},"; } data.pop_back(); diff --git a/src/test/basics/Number_test.cpp b/src/test/basics/Number_test.cpp index 2d2745de14..d704efa27a 100644 --- a/src/test/basics/Number_test.cpp +++ b/src/test/basics/Number_test.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -36,11 +37,11 @@ class Number_test : public beast::unit_test::Suite auto s = to_string(value); std::string out; int count = 0; - for (auto it = s.rbegin(); it != s.rend(); ++it) + for (char const& ch : std::views::reverse(s)) { - if (count != 0 && count % 3 == 0 && (isdigit(*it) != 0)) + if (count != 0 && count % 3 == 0 && (isdigit(ch) != 0)) out.insert(out.begin(), '_'); - out.insert(out.begin(), *it); + out.insert(out.begin(), ch); ++count; } return out; diff --git a/src/test/basics/base58_test.cpp b/src/test/basics/base58_test.cpp index 3c76308813..d2c8d9eabc 100644 --- a/src/test/basics/base58_test.cpp +++ b/src/test/basics/base58_test.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -132,10 +133,10 @@ boost::multiprecision::checked_uint512_t toBoostMP(std::span in) { boost::multiprecision::checked_uint512_t mbp = 0; - for (auto i = in.rbegin(); i != in.rend(); ++i) + for (auto& word : std::views::reverse(in)) { mbp <<= 64; - mbp += *i; + mbp += word; } return mbp; } diff --git a/src/test/beast/aged_associative_container_test.cpp b/src/test/beast/aged_associative_container_test.cpp index 2752ff3127..76be44b793 100644 --- a/src/test/beast/aged_associative_container_test.cpp +++ b/src/test/beast/aged_associative_container_test.cpp @@ -145,7 +145,7 @@ public: } T* - allocate(std::size_t n, T const* = 0) + allocate(std::size_t n, T const* = nullptr) { return static_cast(::operator new(n * sizeof(T))); } diff --git a/src/test/core/Config_test.cpp b/src/test/core/Config_test.cpp index fdac1e450d..38c14b8ac5 100644 --- a/src/test/core/Config_test.cpp +++ b/src/test/core/Config_test.cpp @@ -1136,7 +1136,7 @@ trust-these-validators.gov testZeroPort() { auto const contents = std::regex_replace( - detail::configContents("", ""), std::regex("port\\s*=\\s*\\d+"), "port = 0"); + detail::configContents("", ""), std::regex(R"(port\s*=\s*\d+)"), "port = 0"); try { diff --git a/src/test/csf/ledgers.h b/src/test/csf/ledgers.h index dc5ec5277c..4873519dee 100644 --- a/src/test/csf/ledgers.h +++ b/src/test/csf/ledgers.h @@ -3,7 +3,6 @@ #include #include -#include #include #include #include @@ -13,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -232,8 +232,8 @@ private: class LedgerOracle { using InstanceMap = boost::bimaps::bimap< - boost::bimaps::set_of>, - boost::bimaps::set_of>>; + boost::bimaps::set_of>, + boost::bimaps::set_of>>; using InstanceEntry = InstanceMap::value_type; // Set of all known ledgers; note this is never pruned diff --git a/src/test/jtx/TrustedPublisherServer.h b/src/test/jtx/TrustedPublisherServer.h index 008bbe70c3..f5ee8aac3a 100644 --- a/src/test/jtx/TrustedPublisherServer.h +++ b/src/test/jtx/TrustedPublisherServer.h @@ -188,8 +188,8 @@ public: for (auto const& val : validators) { - data += "{\"validation_public_key\":\"" + strHex(val.masterPublic) + - "\",\"manifest\":\"" + val.manifest + "\"},"; + data += R"({"validation_public_key":")" + strHex(val.masterPublic) + + R"(","manifest":")" + val.manifest + "\"},"; } data.pop_back(); data += "]}"; @@ -201,8 +201,8 @@ public: getList_ = [blob = blob, sig, manifest, version](int interval) { // Build the contents of a version 1 format UNL file std::stringstream l; - l << "{\"blob\":\"" << blob << "\"" << ",\"signature\":\"" << sig << "\"" - << ",\"manifest\":\"" << manifest << "\"" + l << R"({"blob":")" << blob << "\"" << R"(,"signature":")" << sig << "\"" + << R"(,"manifest":")" << manifest << "\"" << ",\"refresh_interval\": " << interval << ",\"version\":" << version << '}'; return l.str(); }; @@ -216,8 +216,8 @@ public: // Use the same set of validators for simplicity for (auto const& val : validators) { - data += "{\"validation_public_key\":\"" + strHex(val.masterPublic) + - "\",\"manifest\":\"" + val.manifest + "\"},"; + data += R"({"validation_public_key":")" + strHex(val.masterPublic) + + R"(","manifest":")" + val.manifest + "\"},"; } data.pop_back(); data += "]}"; @@ -232,13 +232,13 @@ public: std::stringstream l; for (auto const& info : blobInfo) { - l << "{\"blob\":\"" << info.blob << "\"" << ",\"signature\":\"" << info.signature + l << R"({"blob":")" << info.blob << "\"" << R"(,"signature":")" << info.signature << "\"},"; } std::string blobs = l.str(); blobs.pop_back(); l.str(std::string()); - l << "{\"blobs_v2\": [ " << blobs << "],\"manifest\":\"" << manifest << "\"" + l << "{\"blobs_v2\": [ " << blobs << R"(],"manifest":")" << manifest << "\"" << ",\"refresh_interval\": " << interval << ",\"version\":" << (version + 1) << '}'; return l.str(); }; diff --git a/src/test/nodestore/Basics_test.cpp b/src/test/nodestore/Basics_test.cpp index 5565399cc2..7d77b18630 100644 --- a/src/test/nodestore/Basics_test.cpp +++ b/src/test/nodestore/Basics_test.cpp @@ -40,9 +40,9 @@ public: auto batch = createPredictableBatch(kNumObjectsToTest, seedValue); - for (int i = 0; i < batch.size(); ++i) + for (auto const& expected : batch) { - EncodedBlob const encoded(batch[i]); + EncodedBlob const encoded(expected); DecodedBlob decoded(encoded.getKey(), encoded.getData(), encoded.getSize()); @@ -52,7 +52,7 @@ public: { std::shared_ptr const object(decoded.createObject()); - BEAST_EXPECT(isSame(batch[i], object)); + BEAST_EXPECT(isSame(expected, object)); } } } diff --git a/src/test/nodestore/TestBase.h b/src/test/nodestore/TestBase.h index 1254fc51aa..a1245ec963 100644 --- a/src/test/nodestore/TestBase.h +++ b/src/test/nodestore/TestBase.h @@ -124,9 +124,9 @@ public: static void storeBatch(Backend& backend, Batch const& batch) { - for (int i = 0; i < batch.size(); ++i) + for (auto const& object : batch) { - backend.store(batch[i]); + backend.store(object); } } @@ -137,11 +137,11 @@ public: pCopy->clear(); pCopy->reserve(batch.size()); - for (int i = 0; i < batch.size(); ++i) + for (auto const& expected : batch) { std::shared_ptr object; - Status const status = backend.fetch(batch[i]->getHash(), &object); + Status const status = backend.fetch(expected->getHash(), &object); BEAST_EXPECT(status == Status::Ok); @@ -157,11 +157,11 @@ public: void fetchMissing(Backend& backend, Batch const& batch) { - for (int i = 0; i < batch.size(); ++i) + for (auto const& expected : batch) { std::shared_ptr object; - Status const status = backend.fetch(batch[i]->getHash(), &object); + Status const status = backend.fetch(expected->getHash(), &object); BEAST_EXPECT(status == Status::NotFound); } @@ -171,10 +171,8 @@ public: static void storeBatch(Database& db, Batch const& batch) { - for (int i = 0; i < batch.size(); ++i) + for (auto const& object : batch) { - std::shared_ptr const object(batch[i]); - Blob data(object->getData()); db.store(object->getType(), std::move(data), object->getHash(), db.earliestLedgerSeq()); @@ -188,9 +186,9 @@ public: pCopy->clear(); pCopy->reserve(batch.size()); - for (int i = 0; i < batch.size(); ++i) + for (auto const& expected : batch) { - std::shared_ptr const object = db.fetchNodeObject(batch[i]->getHash(), 0); + std::shared_ptr const object = db.fetchNodeObject(expected->getHash(), 0); if (object != nullptr) pCopy->push_back(object); diff --git a/src/test/nodestore/Timing_test.cpp b/src/test/nodestore/Timing_test.cpp index e308d0d5ff..1c296ca44c 100644 --- a/src/test/nodestore/Timing_test.cpp +++ b/src/test/nodestore/Timing_test.cpp @@ -564,10 +564,10 @@ public: char p[2]; p[0] = rand_(gen_) < 50 ? 0 : 1; p[1] = 1 - p[0]; - for (int q = 0; q < 2; ++q) + for (char const op : p) { // NOLINTNEXTLINE(bugprone-switch-missing-default-case) - switch (p[q]) + switch (op) { case 0: { // fetch recent diff --git a/src/test/resource/Logic_test.cpp b/src/test/resource/Logic_test.cpp index f6b4875356..40a81503f1 100644 --- a/src/test/resource/Logic_test.cpp +++ b/src/test/resource/Logic_test.cpp @@ -211,8 +211,8 @@ public: Gossip g[5]; - for (int i = 0; i < 5; ++i) - createGossip(g[i]); + for (auto& gossip : g) + createGossip(gossip); for (int i = 0; i < 5; ++i) logic.importConsumers(std::to_string(i), g[i]); diff --git a/src/test/rpc/AccountInfo_test.cpp b/src/test/rpc/AccountInfo_test.cpp index d061be1f0e..61a11d0b93 100644 --- a/src/test/rpc/AccountInfo_test.cpp +++ b/src/test/rpc/AccountInfo_test.cpp @@ -234,7 +234,7 @@ public: withSigners[jss::account] = alice.human(); withSigners[jss::signer_lists] = true; - auto const withSignersAsString = std::string("{ ") + "\"api_version\": 2, \"account\": \"" + + auto const withSignersAsString = std::string("{ ") + R"("api_version": 2, "account": ")" + alice.human() + "\", " + "\"signer_lists\": asdfggh }"; // Alice has no SignerList yet. diff --git a/src/test/rpc/GetAggregatePrice_test.cpp b/src/test/rpc/GetAggregatePrice_test.cpp index 214bd12183..22c021865d 100644 --- a/src/test/rpc/GetAggregatePrice_test.cpp +++ b/src/test/rpc/GetAggregatePrice_test.cpp @@ -297,13 +297,13 @@ public: OraclesData oracles; prep(env, oracles); - for (int i = 0; i < oracles.size(); ++i) + for (auto& oracleData : oracles) { Oracle oracle( env, - {.owner = oracles[i].first, + {.owner = oracleData.first, // NOLINTNEXTLINE(bugprone-unchecked-optional-access) - .documentID = asUInt(*oracles[i].second), + .documentID = asUInt(*oracleData.second), .fee = baseFee}, false); // push XRP/USD by two ledgers, so this price diff --git a/src/test/rpc/JSONRPC_test.cpp b/src/test/rpc/JSONRPC_test.cpp index 7f6b123533..e18974e7e7 100644 --- a/src/test/rpc/JSONRPC_test.cpp +++ b/src/test/rpc/JSONRPC_test.cpp @@ -2238,7 +2238,7 @@ public: { json::Value req; - json::Reader().parse("{ \"fee_mult_max\" : 1, \"tx_json\" : { } } ", req); + json::Reader().parse(R"({ "fee_mult_max" : 1, "tx_json" : { } } )", req); json::Value const result = checkFee( req, Role::ADMIN, @@ -2275,7 +2275,7 @@ public: { json::Value req; - json::Reader().parse("{ \"fee_mult_max\" : 0, \"tx_json\" : { } } ", req); + json::Reader().parse(R"({ "fee_mult_max" : 0, "tx_json" : { } } )", req); json::Value const result = checkFee( req, Role::ADMIN, diff --git a/src/test/rpc/LedgerEntry_test.cpp b/src/test/rpc/LedgerEntry_test.cpp index 59dbf618f0..c7ef5cef2d 100644 --- a/src/test/rpc/LedgerEntry_test.cpp +++ b/src/test/rpc/LedgerEntry_test.cpp @@ -2917,29 +2917,32 @@ class LedgerEntry_XChain_test : public beast::unit_test::Suite, BEAST_EXPECT( attest[json::Value::UInt(0)].isMember(sfXChainCreateAccountProofSig.jsonName)); json::Value a[kNumAttest]; - for (size_t i = 0; i < kNumAttest; ++i) + for (auto& attestation : a) { - a[i] = attest[json::Value::UInt(0)][sfXChainCreateAccountProofSig.jsonName]; + attestation = attest[json::Value::UInt(0)][sfXChainCreateAccountProofSig.jsonName]; BEAST_EXPECT( - a[i].isMember(jss::Amount) && a[i][jss::Amount].asInt() == 1000 * kDropPerXrp); + attestation.isMember(jss::Amount) && + attestation[jss::Amount].asInt() == 1000 * kDropPerXrp); BEAST_EXPECT( - a[i].isMember(jss::Destination) && a[i][jss::Destination] == scCarol.human()); + attestation.isMember(jss::Destination) && + attestation[jss::Destination] == scCarol.human()); BEAST_EXPECT( - a[i].isMember(sfAttestationSignerAccount.jsonName) && + attestation.isMember(sfAttestationSignerAccount.jsonName) && std::ranges::any_of(signers, [&](Signer const& s) { - return a[i][sfAttestationSignerAccount.jsonName] == s.account.human(); + return attestation[sfAttestationSignerAccount.jsonName] == + s.account.human(); })); BEAST_EXPECT( - a[i].isMember(sfAttestationRewardAccount.jsonName) && + attestation.isMember(sfAttestationRewardAccount.jsonName) && std::ranges::any_of(payee, [&](Account const& account) { - return a[i][sfAttestationRewardAccount.jsonName] == account.human(); + return attestation[sfAttestationRewardAccount.jsonName] == account.human(); })); BEAST_EXPECT( - a[i].isMember(sfWasLockingChainSend.jsonName) && - a[i][sfWasLockingChainSend.jsonName] == 1); + attestation.isMember(sfWasLockingChainSend.jsonName) && + attestation[sfWasLockingChainSend.jsonName] == 1); BEAST_EXPECT( - a[i].isMember(sfSignatureReward.jsonName) && - a[i][sfSignatureReward.jsonName].asInt() == 1 * kDropPerXrp); + attestation.isMember(sfSignatureReward.jsonName) && + attestation[sfSignatureReward.jsonName].asInt() == 1 * kDropPerXrp); } } diff --git a/src/test/rpc/ServerDefinitions_test.cpp b/src/test/rpc/ServerDefinitions_test.cpp index bac1b4f7a5..bf345e6fdf 100644 --- a/src/test/rpc/ServerDefinitions_test.cpp +++ b/src/test/rpc/ServerDefinitions_test.cpp @@ -433,7 +433,7 @@ public: Env env(*this); auto const firstResult = env.rpc("server_definitions"); auto const hash = firstResult[jss::result][jss::hash].asString(); - auto const hashParam = std::string("{ ") + "\"hash\": \"" + hash + "\"}"; + auto const hashParam = std::string("{ ") + R"("hash": ")" + hash + "\"}"; auto const result = env.rpc("json", "server_definitions", hashParam); BEAST_EXPECT(!result[jss::result].isMember(jss::error)); @@ -456,7 +456,7 @@ public: std::string const hash = "54296160385A27154BFA70A239DD8E8FD4CC2DB7BA32D970BA3A5B132CF749" "D1"; - auto const hashParam = std::string("{ ") + "\"hash\": \"" + hash + "\"}"; + auto const hashParam = std::string("{ ") + R"("hash": ")" + hash + "\"}"; auto const result = env.rpc("json", "server_definitions", hashParam); BEAST_EXPECT(!result[jss::result].isMember(jss::error)); diff --git a/src/test/rpc/Version_test.cpp b/src/test/rpc/Version_test.cpp index 20740bfe53..71830c2219 100644 --- a/src/test/rpc/Version_test.cpp +++ b/src/test/rpc/Version_test.cpp @@ -76,7 +76,7 @@ class Version_test : public beast::unit_test::Suite "}"); BEAST_EXPECT(badVersion(re)); - re = env.rpc("json", "version", "{\"api_version\": \"a\"}"); + re = env.rpc("json", "version", R"({"api_version": "a"})"); BEAST_EXPECT(badVersion(re)); } diff --git a/src/test/shamap/SHAMapSync_test.cpp b/src/test/shamap/SHAMapSync_test.cpp index 9e9a490977..bb05ec56df 100644 --- a/src/test/shamap/SHAMapSync_test.cpp +++ b/src/test/shamap/SHAMapSync_test.cpp @@ -18,7 +18,6 @@ #include #include -#include #include #include #include @@ -154,12 +153,12 @@ public: if (b.empty()) fail("", __FILE__, __LINE__); - for (std::size_t i = 0; i < b.size(); ++i) + for (auto& node : b) { // Don't use BEAST_EXPECT here b/c it will be called a // non-deterministic number of times and the number of tests run // should be deterministic - if (!destination.addKnownNode(b[i].first, makeSlice(b[i].second), nullptr) + if (!destination.addKnownNode(node.first, makeSlice(node.second), nullptr) .isUseful()) fail("", __FILE__, __LINE__); } diff --git a/src/tests/libxrpl/json/Value.cpp b/src/tests/libxrpl/json/Value.cpp index 03f565dffb..a1cd8160d7 100644 --- a/src/tests/libxrpl/json/Value.cpp +++ b/src/tests/libxrpl/json/Value.cpp @@ -838,7 +838,7 @@ TEST(json_value, compact) { json::Value j; json::Reader r; - char const* s("{\"array\":[{\"12\":23},{},null,false,0.5]}"); + char const* s(R"({"array":[{"12":23},{},null,false,0.5]})"); auto countLines = [](std::string const& str) { return 1 + std::count_if(str.begin(), str.end(), [](char c) { return c == '\n'; }); diff --git a/src/xrpld/app/ledger/TransactionMaster.h b/src/xrpld/app/ledger/TransactionMaster.h index 5dcad09f51..6d81911510 100644 --- a/src/xrpld/app/ledger/TransactionMaster.h +++ b/src/xrpld/app/ledger/TransactionMaster.h @@ -68,7 +68,7 @@ public: canonicalize(std::shared_ptr* pTransaction); void - sweep(void); + sweep(); TaggedCache& getCache(); diff --git a/src/xrpld/app/ledger/detail/TransactionMaster.cpp b/src/xrpld/app/ledger/detail/TransactionMaster.cpp index 129681b906..ac2aa1aabe 100644 --- a/src/xrpld/app/ledger/detail/TransactionMaster.cpp +++ b/src/xrpld/app/ledger/detail/TransactionMaster.cpp @@ -152,7 +152,7 @@ TransactionMaster::canonicalize(std::shared_ptr* pTransaction) } void -TransactionMaster::sweep(void) +TransactionMaster::sweep() { cache_.sweep(); } diff --git a/src/xrpld/app/rdb/detail/PeerFinder.cpp b/src/xrpld/app/rdb/detail/PeerFinder.cpp index c40e3e42c6..abdcd1c61a 100644 --- a/src/xrpld/app/rdb/detail/PeerFinder.cpp +++ b/src/xrpld/app/rdb/detail/PeerFinder.cpp @@ -147,10 +147,10 @@ updatePeerFinderDB(soci::session& session, int currentSchemaVersion, beast::Jour s.reserve(list.size()); valence.reserve(list.size()); - for (auto iter(list.cbegin()); iter != list.cend(); ++iter) + for (auto const& entry : list) { - s.emplace_back(to_string(iter->endpoint)); - valence.emplace_back(iter->valence); + s.emplace_back(to_string(entry.endpoint)); + valence.emplace_back(entry.valence); } session << "INSERT INTO PeerFinder_BootstrapCache_Next ( " diff --git a/src/xrpld/core/detail/Config.cpp b/src/xrpld/core/detail/Config.cpp index 07c780118a..0706163ab1 100644 --- a/src/xrpld/core/detail/Config.cpp +++ b/src/xrpld/core/detail/Config.cpp @@ -98,7 +98,7 @@ getMemorySize() std::int64_t ram = 0; size_t size = sizeof(ram); - if (sysctl(mib, 2, &ram, &size, NULL, 0) == 0) + if (sysctl(mib, 2, &ram, &size, nullptr, 0) == 0) return static_cast(ram); return 0; @@ -917,7 +917,7 @@ Config::loadFromString(std::string const& fileContents) if (getSingleSection(secConfig, Sections::kAmendmentMajorityTime, strTemp, j_)) { using namespace std::chrono; - boost::regex const re("^\\s*(\\d+)\\s*(minutes|hours|days|weeks)\\s*(\\s+.*)?$"); + boost::regex const re(R"(^\s*(\d+)\s*(minutes|hours|days|weeks)\s*(\s+.*)?$)"); boost::smatch match; if (!boost::regex_match(strTemp, match, re)) { diff --git a/src/xrpld/peerfinder/detail/Bootcache.h b/src/xrpld/peerfinder/detail/Bootcache.h index 5384bb356a..cee03fa322 100644 --- a/src/xrpld/peerfinder/detail/Bootcache.h +++ b/src/xrpld/peerfinder/detail/Bootcache.h @@ -3,7 +3,6 @@ #include #include -#include #include #include #include @@ -13,6 +12,8 @@ #include #include +#include + namespace xrpl::PeerFinder { /** Stores IP addresses useful for gaining initial connections. @@ -62,11 +63,9 @@ private: int valence_; }; - using left_t = boost::bimaps::unordered_set_of< - beast::IP::Endpoint, - boost::hash, - xrpl::equal_to>; - using right_t = boost::bimaps::multiset_of>; + using left_t = boost::bimaps:: + unordered_set_of, std::equal_to<>>; + using right_t = boost::bimaps::multiset_of>; using map_type = boost::bimap; using value_type = map_type::value_type; diff --git a/src/xrpld/peerfinder/detail/SourceStrings.cpp b/src/xrpld/peerfinder/detail/SourceStrings.cpp index 61a3e0c021..7b28db4306 100644 --- a/src/xrpld/peerfinder/detail/SourceStrings.cpp +++ b/src/xrpld/peerfinder/detail/SourceStrings.cpp @@ -32,11 +32,11 @@ public: { results.addresses.resize(0); results.addresses.reserve(strings_.size()); - for (int i = 0; i < strings_.size(); ++i) + for (auto const& str : strings_) { - beast::IP::Endpoint ep(beast::IP::Endpoint::fromString(strings_[i])); + beast::IP::Endpoint ep(beast::IP::Endpoint::fromString(str)); if (isUnspecified(ep)) - ep = beast::IP::Endpoint::fromString(strings_[i]); + ep = beast::IP::Endpoint::fromString(str); if (!isUnspecified(ep)) results.addresses.push_back(ep); } diff --git a/src/xrpld/rpc/handlers/account/GatewayBalances.cpp b/src/xrpld/rpc/handlers/account/GatewayBalances.cpp index bd1681172c..a6730c8e2b 100644 --- a/src/xrpld/rpc/handlers/account/GatewayBalances.cpp +++ b/src/xrpld/rpc/handlers/account/GatewayBalances.cpp @@ -106,8 +106,8 @@ doGatewayBalances(RPC::JsonContext& context) // null is treated as a valid 0-sized array of hotwallet if (hw.isArrayOrNull()) { - for (unsigned i = 0; i < hw.size(); ++i) - valid &= addHotWallet(hw[i]); + for (auto const& wallet : hw) + valid &= addHotWallet(wallet); } else if (hw.isString()) { diff --git a/src/xrpld/rpc/handlers/orderbook/GetAggregatePrice.cpp b/src/xrpld/rpc/handlers/orderbook/GetAggregatePrice.cpp index c1c8712655..d2f596ed8e 100644 --- a/src/xrpld/rpc/handlers/orderbook/GetAggregatePrice.cpp +++ b/src/xrpld/rpc/handlers/orderbook/GetAggregatePrice.cpp @@ -40,8 +40,7 @@ namespace xrpl { using namespace boost::bimaps; // sorted descending by lastUpdateTime, ascending by AssetPrice -using Prices = - bimap>, multiset_of>; +using Prices = bimap>, multiset_of>; /** Calls callback "f" on the ledger-object sle and up to three previous * metadata objects. Stops early if the callback returns true.