From 37fe8414125643396c083518d21a5279b06fa9c8 Mon Sep 17 00:00:00 2001 From: timemarkovqtum Date: Fri, 7 Jun 2024 11:40:59 +0200 Subject: [PATCH] Compile fix for c++20 --- src/cryptopp/algparam.h | 6 +++- src/cryptopp/trdlocal.cpp | 4 +++ src/eth_client/libdevcore/CommonData.h | 4 +-- src/eth_client/libdevcore/vector_ref.h | 2 +- src/eth_client/libdevcrypto/Common.cpp | 11 ++++++-- src/eth_client/libethereum/State.cpp | 12 ++++++-- .../json_spirit/json_spirit_reader_template.h | 28 ++++++++++--------- 7 files changed, 46 insertions(+), 21 deletions(-) diff --git a/src/cryptopp/algparam.h b/src/cryptopp/algparam.h index 333129b3f5..4a5c7e338e 100644 --- a/src/cryptopp/algparam.h +++ b/src/cryptopp/algparam.h @@ -320,7 +320,11 @@ class CRYPTOPP_DLL AlgorithmParametersBase virtual ~AlgorithmParametersBase() CRYPTOPP_THROW { #ifdef CRYPTOPP_UNCAUGHT_EXCEPTION_AVAILABLE - if (!std::uncaught_exception()) + #ifdef QTUM_BUILD + if (!std::uncaught_exceptions()) + #else + if (!std::uncaught_exception()) + #endif #else try #endif diff --git a/src/cryptopp/trdlocal.cpp b/src/cryptopp/trdlocal.cpp index 0d9d42f1ac..20494b5482 100644 --- a/src/cryptopp/trdlocal.cpp +++ b/src/cryptopp/trdlocal.cpp @@ -45,7 +45,11 @@ ThreadLocalStorage::ThreadLocalStorage() ThreadLocalStorage::~ThreadLocalStorage() CRYPTOPP_THROW { #ifdef CRYPTOPP_UNCAUGHT_EXCEPTION_AVAILABLE + #ifdef QTUM_BUILD + if (!std::uncaught_exceptions()) + #else if (!std::uncaught_exception()) + #endif #else try #endif diff --git a/src/eth_client/libdevcore/CommonData.h b/src/eth_client/libdevcore/CommonData.h index d1dde6ae1c..3a66c0e51d 100644 --- a/src/eth_client/libdevcore/CommonData.h +++ b/src/eth_client/libdevcore/CommonData.h @@ -206,7 +206,7 @@ inline unsigned bytesRequired(T _i) template void trimFront(T& _t, unsigned _elements) { - static_assert(std::is_pod::value, ""); + static_assert(std::is_trivial::value && std::is_standard_layout::value, ""); memmove(_t.data(), _t.data() + _elements, (_t.size() - _elements) * sizeof(_t[0])); _t.resize(_t.size() - _elements); } @@ -216,7 +216,7 @@ void trimFront(T& _t, unsigned _elements) template void pushFront(T& _t, _U _e) { - static_assert(std::is_pod::value, ""); + static_assert(std::is_trivial::value && std::is_standard_layout::value, ""); _t.push_back(_e); memmove(_t.data() + 1, _t.data(), (_t.size() - 1) * sizeof(_e)); _t[0] = _e; diff --git a/src/eth_client/libdevcore/vector_ref.h b/src/eth_client/libdevcore/vector_ref.h index 35a9eff0b3..b2a3cfadba 100644 --- a/src/eth_client/libdevcore/vector_ref.h +++ b/src/eth_client/libdevcore/vector_ref.h @@ -28,7 +28,7 @@ class vector_ref using element_type = _T; using mutable_value_type = typename std::conditional::value, typename std::remove_const<_T>::type, _T>::type; - static_assert(std::is_pod::value, "vector_ref can only be used with PODs due to its low-level treatment of data."); + static_assert(std::is_trivial::value && std::is_standard_layout::value, "vector_ref can only be used with PODs due to its low-level treatment of data."); vector_ref(): m_data(nullptr), m_count(0) {} /// Creates a new vector_ref to point to @a _count elements starting at @a _data. diff --git a/src/eth_client/libdevcrypto/Common.cpp b/src/eth_client/libdevcrypto/Common.cpp index 9e7e4b7a7f..33bf1880fc 100644 --- a/src/eth_client/libdevcrypto/Common.cpp +++ b/src/eth_client/libdevcrypto/Common.cpp @@ -25,11 +25,18 @@ using namespace dev::crypto; namespace { +struct Secp256k1ContextDeleter +{ + void operator()(secp256k1_context* ctx) const { + secp256k1_context_destroy(ctx); + } +}; + secp256k1_context const* getCtx() { - static std::unique_ptr s_ctx{ + static std::unique_ptr s_ctx{ secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY), - &secp256k1_context_destroy + Secp256k1ContextDeleter{} }; return s_ctx.get(); } diff --git a/src/eth_client/libethereum/State.cpp b/src/eth_client/libethereum/State.cpp index 9e36e0c092..4c91fcc41c 100644 --- a/src/eth_client/libethereum/State.cpp +++ b/src/eth_client/libethereum/State.cpp @@ -712,8 +712,16 @@ std::ostream& dev::eth::operator<<(std::ostream& _out, State const& _s) if (r) { SecureTrieDB memdb(const_cast(&_s.m_db), r[2].toHash()); // promise we won't alter the overlay! :) - for (auto const& j: memdb) - mem[j.first] = RLP(j.second).toInt(), back.insert(j.first); + for (auto const& j: memdb) { + // mem[j.first] = RLP(j.second).toInt(), back.insert(j.first); + // The above line fails to compile in C++ 20 due to an invalid static_cast, replacement: + if (mem.find(j.first) == mem.end()) { + mem.insert({j.first, RLP(j.second).toInt()}); + } else { + mem.at(j.first) = RLP(j.second).toInt(); + } + back.insert(j.first); + } } if (cache) for (auto const& j: cache->storageOverlay()) diff --git a/src/eth_client/utils/json_spirit/json_spirit_reader_template.h b/src/eth_client/utils/json_spirit/json_spirit_reader_template.h index 81cded4346..d0bfc1a83f 100644 --- a/src/eth_client/utils/json_spirit/json_spirit_reader_template.h +++ b/src/eth_client/utils/json_spirit/json_spirit_reader_template.h @@ -11,10 +11,12 @@ //#define BOOST_SPIRIT_THREADSAFE // uncomment for multithreaded use, requires linking to boost.thread -#include +#include #include #include +#include + #if BOOST_VERSION >= 103800 #include #include @@ -428,18 +430,18 @@ namespace json_spirit typedef boost::function< void( boost::int64_t ) > Int_action; typedef boost::function< void( boost::uint64_t ) > Uint64_action; - Char_action begin_obj ( boost::bind( &Semantic_actions_t::begin_obj, &self.actions_, _1 ) ); - Char_action end_obj ( boost::bind( &Semantic_actions_t::end_obj, &self.actions_, _1 ) ); - Char_action begin_array( boost::bind( &Semantic_actions_t::begin_array, &self.actions_, _1 ) ); - Char_action end_array ( boost::bind( &Semantic_actions_t::end_array, &self.actions_, _1 ) ); - Str_action new_name ( boost::bind( &Semantic_actions_t::new_name, &self.actions_, _1, _2 ) ); - Str_action new_str ( boost::bind( &Semantic_actions_t::new_str, &self.actions_, _1, _2 ) ); - Str_action new_true ( boost::bind( &Semantic_actions_t::new_true, &self.actions_, _1, _2 ) ); - Str_action new_false ( boost::bind( &Semantic_actions_t::new_false, &self.actions_, _1, _2 ) ); - Str_action new_null ( boost::bind( &Semantic_actions_t::new_null, &self.actions_, _1, _2 ) ); - Real_action new_real ( boost::bind( &Semantic_actions_t::new_real, &self.actions_, _1 ) ); - Int_action new_int ( boost::bind( &Semantic_actions_t::new_int, &self.actions_, _1 ) ); - Uint64_action new_uint64 ( boost::bind( &Semantic_actions_t::new_uint64, &self.actions_, _1 ) ); + Char_action begin_obj ( boost::bind( &Semantic_actions_t::begin_obj, &self.actions_, std::placeholders::_1 ) ); + Char_action end_obj ( boost::bind( &Semantic_actions_t::end_obj, &self.actions_, std::placeholders::_1 ) ); + Char_action begin_array( boost::bind( &Semantic_actions_t::begin_array, &self.actions_, std::placeholders::_1 ) ); + Char_action end_array ( boost::bind( &Semantic_actions_t::end_array, &self.actions_, std::placeholders::_1 ) ); + Str_action new_name ( boost::bind( &Semantic_actions_t::new_name, &self.actions_, std::placeholders::_1, std::placeholders::_2 ) ); + Str_action new_str ( boost::bind( &Semantic_actions_t::new_str, &self.actions_, std::placeholders::_1, std::placeholders::_2 ) ); + Str_action new_true ( boost::bind( &Semantic_actions_t::new_true, &self.actions_, std::placeholders::_1, std::placeholders::_2 ) ); + Str_action new_false ( boost::bind( &Semantic_actions_t::new_false, &self.actions_, std::placeholders::_1, std::placeholders::_2 ) ); + Str_action new_null ( boost::bind( &Semantic_actions_t::new_null, &self.actions_, std::placeholders::_1, std::placeholders::_2 ) ); + Real_action new_real ( boost::bind( &Semantic_actions_t::new_real, &self.actions_, std::placeholders::_1 ) ); + Int_action new_int ( boost::bind( &Semantic_actions_t::new_int, &self.actions_, std::placeholders::_1 ) ); + Uint64_action new_uint64 ( boost::bind( &Semantic_actions_t::new_uint64, &self.actions_, std::placeholders::_1 ) ); // actual grammer