diff --git a/src/ripple/app/misc/impl/ValidatorList.cpp b/src/ripple/app/misc/impl/ValidatorList.cpp index 3d8dce509..09f774f8a 100644 --- a/src/ripple/app/misc/impl/ValidatorList.cpp +++ b/src/ripple/app/misc/impl/ValidatorList.cpp @@ -99,7 +99,7 @@ void ValidatorList::PublisherListStats::mergeDispositions( PublisherListStats const& src) { - for (auto const [disp, count] : src.dispositions) + for (auto const& [disp, count] : src.dispositions) { dispositions[disp] += count; } diff --git a/src/ripple/app/misc/impl/ValidatorSite.cpp b/src/ripple/app/misc/impl/ValidatorSite.cpp index e26ce7a87..34195a9d1 100644 --- a/src/ripple/app/misc/impl/ValidatorSite.cpp +++ b/src/ripple/app/misc/impl/ValidatorSite.cpp @@ -408,7 +408,7 @@ ValidatorSite::parseJsonResponse( sites_[siteIdx].lastRefreshStatus.emplace( Site::Status{clock_type::now(), applyResult.bestDisposition(), ""}); - for (auto const [disp, count] : applyResult.dispositions) + for (auto const& [disp, count] : applyResult.dispositions) { switch (disp) { diff --git a/src/ripple/overlay/impl/ConnectAttempt.cpp b/src/ripple/overlay/impl/ConnectAttempt.cpp index c723b950b..911215d80 100644 --- a/src/ripple/overlay/impl/ConnectAttempt.cpp +++ b/src/ripple/overlay/impl/ConnectAttempt.cpp @@ -293,7 +293,7 @@ ConnectAttempt::processResponse() Json::Reader r; std::string s; s.reserve(boost::asio::buffer_size(response_.body().data())); - for (auto const& buffer : response_.body().data()) + for (auto const buffer : response_.body().data()) s.append( boost::asio::buffer_cast(buffer), boost::asio::buffer_size(buffer)); diff --git a/src/ripple/overlay/impl/PeerImp.cpp b/src/ripple/overlay/impl/PeerImp.cpp index 68f3d61d7..06221b6bb 100644 --- a/src/ripple/overlay/impl/PeerImp.cpp +++ b/src/ripple/overlay/impl/PeerImp.cpp @@ -2168,7 +2168,7 @@ PeerImp::onValidatorListMessage( } // Log based on all the results. - for (auto const [disp, count] : applyResult.dispositions) + for (auto const& [disp, count] : applyResult.dispositions) { switch (disp) { diff --git a/src/ripple/rpc/impl/ServerHandlerImp.cpp b/src/ripple/rpc/impl/ServerHandlerImp.cpp index b8d9567b0..fd056a346 100644 --- a/src/ripple/rpc/impl/ServerHandlerImp.cpp +++ b/src/ripple/rpc/impl/ServerHandlerImp.cpp @@ -264,7 +264,9 @@ buffers_to_string(ConstBufferSequence const& bs) using boost::asio::buffer_size; std::string s; s.reserve(buffer_size(bs)); - for (auto const& b : bs) + // Use auto&& so the right thing happens whether bs returns a copy or + // a reference + for (auto&& b : bs) s.append(buffer_cast(b), buffer_size(b)); return s; } diff --git a/src/ripple/server/SimpleWriter.h b/src/ripple/server/SimpleWriter.h index 97819556b..03582c001 100644 --- a/src/ripple/server/SimpleWriter.h +++ b/src/ripple/server/SimpleWriter.h @@ -66,7 +66,7 @@ public: auto const& buf = sb_.data(); std::vector result; result.reserve(std::distance(buf.begin(), buf.end())); - for (auto const& b : buf) + for (auto const b : buf) result.push_back(b); return result; } diff --git a/src/test/app/Check_test.cpp b/src/test/app/Check_test.cpp index 3552d24bb..54e5d6d15 100644 --- a/src/test/app/Check_test.cpp +++ b/src/test/app/Check_test.cpp @@ -865,7 +865,7 @@ class Check_test : public beast::unit_test::suite // featureMultiSignReserve changes the reserve on a SignerList, so // check both before and after. FeatureBitset const allSupported{supported_amendments()}; - for (auto const features : + for (auto const& features : {allSupported - featureMultiSignReserve, allSupported | featureMultiSignReserve}) { @@ -1514,7 +1514,7 @@ class Check_test : public beast::unit_test::suite // featureMultiSignReserve changes the reserve on a SignerList, so // check both before and after. FeatureBitset const allSupported{supported_amendments()}; - for (auto const features : + for (auto const& features : {allSupported - featureMultiSignReserve, allSupported | featureMultiSignReserve}) { diff --git a/src/test/app/Offer_test.cpp b/src/test/app/Offer_test.cpp index 8e6e55b4e..606b9f569 100644 --- a/src/test/app/Offer_test.cpp +++ b/src/test/app/Offer_test.cpp @@ -882,7 +882,7 @@ public: // // fix1578 changes the return code. Verify expected behavior // without and with fix1578. - for (auto const tweakedFeatures : + for (auto const& tweakedFeatures : {features - fix1578, features | fix1578}) { Env env{*this, tweakedFeatures}; diff --git a/src/test/csf/BasicNetwork_test.cpp b/src/test/csf/BasicNetwork_test.cpp index 3ea3ef63a..f3b18216a 100644 --- a/src/test/csf/BasicNetwork_test.cpp +++ b/src/test/csf/BasicNetwork_test.cpp @@ -49,7 +49,7 @@ public: auto t = scheduler.in(1s, [&] { set.insert(0); }); if (id == 0) { - for (auto const& link : net.links(this)) + for (auto const link : net.links(this)) net.send(this, link.target, [&, to = link.target] { to->receive(net, this, 1); }); @@ -68,7 +68,7 @@ public: ++m; if (m < 5) { - for (auto const& link : net.links(this)) + for (auto const link : net.links(this)) net.send(this, link.target, [&, mm = m, to = link.target] { to->receive(net, this, mm); }); diff --git a/src/test/csf/Peer.h b/src/test/csf/Peer.h index 3b972493a..2f3ce1931 100644 --- a/src/test/csf/Peer.h +++ b/src/test/csf/Peer.h @@ -344,7 +344,7 @@ struct Peer bool trusts(PeerID const& oId) { - for (auto const& p : trustGraph.trustedPeers(this)) + for (auto const p : trustGraph.trustedPeers(this)) if (p->id == oId) return true; return false; @@ -404,7 +404,7 @@ struct Peer using namespace std::chrono_literals; SimDuration minDuration{10s}; - for (auto const& link : net.links(this)) + for (auto const link : net.links(this)) { minDuration = std::min(minDuration, link.data.delay); @@ -451,7 +451,7 @@ struct Peer using namespace std::chrono_literals; SimDuration minDuration{10s}; - for (auto const& link : net.links(this)) + for (auto const link : net.links(this)) { minDuration = std::min(minDuration, link.data.delay); // Send a message to neighbors to find the tx set @@ -741,7 +741,7 @@ struct Peer void send(BroadcastMesg const& bm, PeerID from) { - for (auto const& link : net.links(this)) + for (auto const link : net.links(this)) { if (link.target->id != from && link.target->id != bm.origin) { @@ -848,7 +848,7 @@ struct Peer getQuorumKeys() { hash_set keys; - for (auto const& p : trustGraph.trustedPeers(this)) + for (auto const p : trustGraph.trustedPeers(this)) keys.insert(p->key); return {quorum, keys}; } diff --git a/src/test/csf/TrustGraph.h b/src/test/csf/TrustGraph.h index c6c216053..31bb85340 100644 --- a/src/test/csf/TrustGraph.h +++ b/src/test/csf/TrustGraph.h @@ -126,7 +126,7 @@ public: using UNL = std::set; std::set unique; - for (Peer const& peer : graph_.outVertices()) + for (Peer const peer : graph_.outVertices()) { unique.emplace( std::begin(trustedPeers(peer)), std::end(trustedPeers(peer))); diff --git a/src/test/ledger/Invariants_test.cpp b/src/test/ledger/Invariants_test.cpp index 4b0271e7e..f07f33922 100644 --- a/src/test/ledger/Invariants_test.cpp +++ b/src/test/ledger/Invariants_test.cpp @@ -75,7 +75,7 @@ class Invariants_test : public beast::unit_test::suite return; TER terActual = tesSUCCESS; - for (TER const terExpect : ters) + for (TER const& terExpect : ters) { terActual = ac.checkInvariants(terActual, fee); BEAST_EXPECT(terExpect == terActual); diff --git a/src/test/rpc/NoRipple_test.cpp b/src/test/rpc/NoRipple_test.cpp index 69c88d144..aa7358f77 100644 --- a/src/test/rpc/NoRipple_test.cpp +++ b/src/test/rpc/NoRipple_test.cpp @@ -84,7 +84,7 @@ public: // fix1578 changes the return code. Verify expected behavior // without and with fix1578. - for (auto const tweakedFeatures : + for (auto const& tweakedFeatures : {features - fix1578, features | fix1578}) { Env env(*this, tweakedFeatures);