From b28f25774a0a8f84cf9a342126c1b821340f13ed Mon Sep 17 00:00:00 2001 From: "W. J. van der Laan" Date: Thu, 22 Jul 2021 14:53:43 +0200 Subject: [PATCH] Merge bitcoin/bitcoin#22481: mempool: apply rule of 5 to epochguard.h, fix compiler warnings 7b3a20b2602f902c344a615f23f8f0280b6f6bcc mempool: apply rule of 5 to epochguard.h, fix compiler warnings (Jon Atack) Pull request description: Apply the rule of five to `src/util/epochguard.h::{Epoch, Marker}` for safety, which also nicely fixes the `-Wdeprecated-copy` compiler warnings with Clang 13. References: - https://en.cppreference.com/w/cpp/language/rule_of_three - https://www.stroustrup.com/C++11FAQ.html#default - https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rc-five
Compiler warnings fixed

```bash In file included from policy/rbf.cpp:5: In file included from ./policy/rbf.h:8: In file included from ./txmempool.h:24: ./util/epochguard.h:53:17: warning: definition of implicit copy constructor for 'Marker' is deprecated because it has a user-declared copy assignment operator [-Wdeprecated-copy] Marker& operator=(const Marker&) = delete; ^ ./txmempool.h:81:7: note: in implicit copy constructor for 'Epoch::Marker' first required here class CTxMemPoolEntry ^ policy/rbf.cpp:29:29: note: in implicit copy constructor for 'CTxMemPoolEntry' first required here CTxMemPoolEntry entry = *pool.mapTx.find(tx.GetHash()); ``` ```bash In file included from txmempool.cpp:6: In file included from ./txmempool.h:24: ./util/epochguard.h:53:17: warning: definition of implicit copy constructor for 'Marker' is deprecated because it has a user-declared copy assignment operator [-Wdeprecated-copy] Marker& operator=(const Marker&) = delete; ^ ./txmempool.h:81:7: note: in implicit copy constructor for 'Epoch::Marker' first required here class CTxMemPoolEntry ^ /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/ext/new_allocator.h:150:23: note: in implicit copy constructor for 'CTxMemPoolEntry' first required here { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); } ^ /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/alloc_traits.h:512:8: note: in instantiation of function template specialization '__gnu_cxx::new_allocator>>>>>>>::construct' requested here __a.construct(__p, std::forward<_Args>(__args)...); ^ /usr/include/boost/multi_index_container.hpp:655:24: note: in instantiation of function template specialization 'std::allocator_traits>>>>>>>>::construct' requested here node_alloc_traits::construct( ^ /usr/include/boost/multi_index/detail/index_base.hpp:108:15: note: in instantiation of member function 'boost::multi_index::multi_index_container, boost::multi_index::hashed_unique, mempoolentry_wtxid, SaltedTxidHasher>, boost::multi_index::ordered_non_unique, boost::multi_index::identity, CompareTxMemPoolEntryByDescendantScore>, boost::multi_index::ordered_non_unique, boost::multi_index::identity, CompareTxMemPoolEntryByEntryTime>, boost::multi_index::ordered_non_unique, boost::multi_index::identity, CompareTxMemPoolEntryByAncestorFee>>>::construct_value' requested here final().construct_value(x,v); ^ /usr/include/boost/multi_index/detail/ord_index_impl.hpp:770:33: note: (skipping 5 contexts in backtrace; use -ftemplate-backtrace-limit=0 to see all) final_node_type* res=super::insert_(v,x,variant); ^ /usr/include/boost/multi_index_container.hpp:693:33: note: in instantiation of function template specialization 'boost::multi_index::detail::hashed_index, boost::multi_index::detail::nth_layer<1, CTxMemPoolEntry, boost::multi_index::indexed_by, boost::multi_index::hashed_unique, mempoolentry_wtxid, SaltedTxidHasher>, boost::multi_index::ordered_non_unique, boost::multi_index::identity, CompareTxMemPoolEntryByDescendantScore>, boost::multi_index::ordered_non_unique, boost::multi_index::identity, CompareTxMemPoolEntryByEntryTime>, boost::multi_index::ordered_non_unique, boost::multi_index::identity, CompareTxMemPoolEntryByAncestorFee>>, std::allocator>, boost::mpl::vector0<>, boost::multi_index::detail::hashed_unique_tag>::insert_' requested here final_node_type* res=super::insert_(v,x,variant); ^ /usr/include/boost/multi_index_container.hpp:705:12: note: in instantiation of function template specialization 'boost::multi_index::multi_index_container, boost::multi_index::hashed_unique, mempoolentry_wtxid, SaltedTxidHasher>, boost::multi_index::ordered_non_unique, boost::multi_index::identity, CompareTxMemPoolEntryByDescendantScore>, boost::multi_index::ordered_non_unique, boost::multi_index::identity, CompareTxMemPoolEntryByEntryTime>, boost::multi_index::ordered_non_unique, boost::multi_index::identity, CompareTxMemPoolEntryByAncestorFee>>>::insert_' requested here return insert_(v,detail::lvalue_tag()); ^ /usr/include/boost/multi_index/detail/index_base.hpp:213:21: note: in instantiation of member function 'boost::multi_index::multi_index_container, boost::multi_index::hashed_unique, mempoolentry_wtxid, SaltedTxidHasher>, boost::multi_index::ordered_non_unique, boost::multi_index::identity, CompareTxMemPoolEntryByDescendantScore>, boost::multi_index::ordered_non_unique, boost::multi_index::identity, CompareTxMemPoolEntryByEntryTime>, boost::multi_index::ordered_non_unique, boost::multi_index::identity, CompareTxMemPoolEntryByAncestorFee>>>::insert_' requested here {return final().insert_(x);} ^ /usr/include/boost/multi_index/hashed_index.hpp:284:46: note: in instantiation of member function 'boost::multi_index::detail::index_base, boost::multi_index::hashed_unique, mempoolentry_wtxid, SaltedTxidHasher>, boost::multi_index::ordered_non_unique, boost::multi_index::identity, CompareTxMemPoolEntryByDescendantScore>, boost::multi_index::ordered_non_unique, boost::multi_index::identity, CompareTxMemPoolEntryByEntryTime>, boost::multi_index::ordered_non_unique, boost::multi_index::identity, CompareTxMemPoolEntryByAncestorFee>>, std::allocator>::final_insert_' requested here std::pair p=this->final_insert_(x); ^ txmempool.cpp:363:53: note: in instantiation of member function 'boost::multi_index::detail::hashed_index, boost::multi_index::detail::nth_layer<1, CTxMemPoolEntry, boost::multi_index::indexed_by, boost::multi_index::hashed_unique, mempoolentry_wtxid, SaltedTxidHasher>, boost::multi_index::ordered_non_unique, boost::multi_index::identity, CompareTxMemPoolEntryByDescendantScore>, boost::multi_index::ordered_non_unique, boost::multi_index::identity, CompareTxMemPoolEntryByEntryTime>, boost::multi_index::ordered_non_unique, boost::multi_index::identity, CompareTxMemPoolEntryByAncestorFee>>, std::allocator>, boost::mpl::vector0<>, boost::multi_index::detail::hashed_unique_tag>::insert' requested here indexed_transaction_set::iterator newit = mapTx.insert(entry).first; ``` ```bash In file included from test/fuzz/policy_estimator.cpp:9: In file included from ./test/fuzz/util.h:27: In file included from ./txmempool.h:24: ./util/epochguard.h:53:17: warning: definition of implicit copy constructor for 'Marker' is deprecated because it has a user-declared copy assignment operator [-Wdeprecated-copy] Marker& operator=(const Marker&) = delete; ^ ./txmempool.h:81:7: note: in implicit copy constructor for 'Epoch::Marker' first required here class CTxMemPoolEntry ^ /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/ext/new_allocator.h:150:23: note: in implicit move constructor for 'CTxMemPoolEntry' first required here { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); } ^ /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/alloc_traits.h:512:8: note: in instantiation of function template specialization '__gnu_cxx::new_allocator::construct' requested here __a.construct(__p, std::forward<_Args>(__args)...); ^ /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/vector.tcc:115:21: note: in instantiation of function template specialization 'std::allocator_traits>::construct' requested here _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish, ^ /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_vector.h:1204:9: note: in instantiation of function template specialization 'std::vector::emplace_back' requested here { emplace_back(std::move(__x)); } ^ test/fuzz/policy_estimator.cpp:49:37: note: in instantiation of member function 'std::vector::push_back' requested here mempool_entries.push_back(ConsumeTxMemPoolEntry(fuzzed_data_provider, tx)); ```

ACKs for top commit: laanwj: Code review ACK 7b3a20b2602f902c344a615f23f8f0280b6f6bcc vasild: ACK 7b3a20b2602f902c344a615f23f8f0280b6f6bcc Tree-SHA512: 0406dfcec180152d4f9ed07cbc2f406ad739b41f9c9cb38f8c75159c15d9d8a9a5c7526765966e40d695d265c178f6a80152e7edf82da344a65e55938dddb63d --- src/util/epochguard.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/util/epochguard.h b/src/util/epochguard.h index 1570ec4eb4..3e63e093da 100644 --- a/src/util/epochguard.h +++ b/src/util/epochguard.h @@ -40,6 +40,9 @@ public: Epoch() = default; Epoch(const Epoch&) = delete; Epoch& operator=(const Epoch&) = delete; + Epoch(Epoch&&) = delete; + Epoch& operator=(Epoch&&) = delete; + ~Epoch() = default; bool guarded() const { return m_guarded; } @@ -51,6 +54,13 @@ public: // only allow modification via Epoch member functions friend class Epoch; Marker& operator=(const Marker&) = delete; + + public: + Marker() = default; + Marker(const Marker&) = default; + Marker(Marker&&) = delete; + Marker& operator=(Marker&&) = delete; + ~Marker() = default; }; class SCOPED_LOCKABLE Guard