Skip to content

Commit

Permalink
Compile fix for c++20
Browse files Browse the repository at this point in the history
  • Loading branch information
timemarkovqtum committed Jun 7, 2024
1 parent 4c8bb4e commit 37fe841
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 21 deletions.
6 changes: 5 additions & 1 deletion src/cryptopp/algparam.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/cryptopp/trdlocal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/eth_client/libdevcore/CommonData.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ inline unsigned bytesRequired(T _i)
template <class T>
void trimFront(T& _t, unsigned _elements)
{
static_assert(std::is_pod<typename T::value_type>::value, "");
static_assert(std::is_trivial<typename T::value_type>::value && std::is_standard_layout<typename T::value_type>::value, "");
memmove(_t.data(), _t.data() + _elements, (_t.size() - _elements) * sizeof(_t[0]));
_t.resize(_t.size() - _elements);
}
Expand All @@ -216,7 +216,7 @@ void trimFront(T& _t, unsigned _elements)
template <class T, class _U>
void pushFront(T& _t, _U _e)
{
static_assert(std::is_pod<typename T::value_type>::value, "");
static_assert(std::is_trivial<typename T::value_type>::value && std::is_standard_layout<typename T::value_type>::value, "");
_t.push_back(_e);
memmove(_t.data() + 1, _t.data(), (_t.size() - 1) * sizeof(_e));
_t[0] = _e;
Expand Down
2 changes: 1 addition & 1 deletion src/eth_client/libdevcore/vector_ref.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class vector_ref
using element_type = _T;
using mutable_value_type = typename std::conditional<std::is_const<_T>::value, typename std::remove_const<_T>::type, _T>::type;

static_assert(std::is_pod<value_type>::value, "vector_ref can only be used with PODs due to its low-level treatment of data.");
static_assert(std::is_trivial<value_type>::value && std::is_standard_layout<value_type>::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.
Expand Down
11 changes: 9 additions & 2 deletions src/eth_client/libdevcrypto/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<secp256k1_context, decltype(&secp256k1_context_destroy)> s_ctx{
static std::unique_ptr<secp256k1_context, Secp256k1ContextDeleter> s_ctx{
secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY),
&secp256k1_context_destroy
Secp256k1ContextDeleter{}
};
return s_ctx.get();
}
Expand Down
12 changes: 10 additions & 2 deletions src/eth_client/libethereum/State.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -712,8 +712,16 @@ std::ostream& dev::eth::operator<<(std::ostream& _out, State const& _s)
if (r)
{
SecureTrieDB<h256, OverlayDB> memdb(const_cast<OverlayDB*>(&_s.m_db), r[2].toHash<h256>()); // promise we won't alter the overlay! :)
for (auto const& j: memdb)
mem[j.first] = RLP(j.second).toInt<u256>(), back.insert(j.first);
for (auto const& j: memdb) {
// mem[j.first] = RLP(j.second).toInt<u256>(), 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<u256>()});
} else {
mem.at(j.first) = RLP(j.second).toInt<u256>();
}
back.insert(j.first);
}
}
if (cache)
for (auto const& j: cache->storageOverlay())
Expand Down
28 changes: 15 additions & 13 deletions src/eth_client/utils/json_spirit/json_spirit_reader_template.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@

//#define BOOST_SPIRIT_THREADSAFE // uncomment for multithreaded use, requires linking to boost.thread

#include <boost/bind.hpp>
#include <boost/bind/bind.hpp>
#include <boost/function.hpp>
#include <boost/version.hpp>

#include <functional>

#if BOOST_VERSION >= 103800
#include <boost/spirit/include/classic_core.hpp>
#include <boost/spirit/include/classic_confix.hpp>
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 37fe841

Please sign in to comment.