Relax static_asserts in src/lmdb

This commit is contained in:
Lee Clagett 2024-10-09 16:34:25 -04:00
parent 9866a0e902
commit bd2869650a
4 changed files with 5 additions and 3 deletions

View File

@ -133,6 +133,7 @@ namespace lmdb
//! \pre `!is_end()` \return Current key //! \pre `!is_end()` \return Current key
K get_key() const noexcept K get_key() const noexcept
{ {
static_assert(std::is_trivially_copyable<K>(), "key is not memcpy safe");
assert(!is_end()); assert(!is_end());
K out; K out;
std::memcpy(std::addressof(out), key.data(), sizeof(out)); std::memcpy(std::addressof(out), key.data(), sizeof(out));

View File

@ -55,7 +55,7 @@ namespace lmdb
static expect<F> get_value(MDB_val value) noexcept static expect<F> get_value(MDB_val value) noexcept
{ {
static_assert(std::is_same<U, V>(), "bad MONERO_FIELD?"); static_assert(std::is_same<U, V>(), "bad MONERO_FIELD?");
static_assert(std::is_pod<F>(), "F must be POD"); static_assert(std::is_trivially_copyable<F>(), "F must be memcpy safe");
static_assert(sizeof(F) + offset <= sizeof(U), "bad field type and/or offset"); static_assert(sizeof(F) + offset <= sizeof(U), "bad field type and/or offset");
if (value.mv_size != sizeof(U)) if (value.mv_size != sizeof(U))

View File

@ -111,6 +111,7 @@ namespace lmdb
template<typename T, std::size_t offset = 0> template<typename T, std::size_t offset = 0>
inline int less(MDB_val const* left, MDB_val const* right) noexcept inline int less(MDB_val const* left, MDB_val const* right) noexcept
{ {
static_assert(std::is_trivially_copyable<T>(), "memcpy will not work");
if (!left || !right || left->mv_size < sizeof(T) + offset || right->mv_size < sizeof(T) + offset) if (!left || !right || left->mv_size < sizeof(T) + offset || right->mv_size < sizeof(T) + offset)
{ {
assert("invalid use of custom comparison" == 0); assert("invalid use of custom comparison" == 0);

View File

@ -162,8 +162,8 @@ namespace lmdb
G get_value() const noexcept G get_value() const noexcept
{ {
static_assert(std::is_same<U, T>(), "bad MONERO_FIELD usage?"); static_assert(std::is_same<U, T>(), "bad MONERO_FIELD usage?");
static_assert(std::is_pod<U>(), "value type must be pod"); static_assert(std::is_trivially_copyable<U>(), "value type must be memcpy safe");
static_assert(std::is_pod<G>(), "field type must be pod"); static_assert(std::is_trivially_copyable<G>(), "field type must be memcpy safe");
static_assert(sizeof(G) + uoffset <= sizeof(U), "bad field and/or offset"); static_assert(sizeof(G) + uoffset <= sizeof(U), "bad field and/or offset");
assert(sizeof(G) + uoffset <= values.size()); assert(sizeof(G) + uoffset <= values.size());
assert(!is_end()); assert(!is_end());