Skip to content

Commit

Permalink
Remove hacks for lack of C++17 constexpr support in gcc/clang.
Browse files Browse the repository at this point in the history
  • Loading branch information
evoskuil committed Jan 29, 2025
1 parent 574a62e commit a31f722
Show file tree
Hide file tree
Showing 32 changed files with 114 additions and 206 deletions.
4 changes: 2 additions & 2 deletions include/bitcoin/system/chain/operation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ class BC_API operation
static constexpr opcode opcode_from_version(uint8_t value) NOEXCEPT;
static constexpr opcode opcode_from_positive(uint8_t value) NOEXCEPT;

static VCONSTEXPR opcode minimal_opcode_from_data(
static constexpr opcode minimal_opcode_from_data(
const data_chunk& data) NOEXCEPT;
static VCONSTEXPR opcode nominal_opcode_from_data(
static constexpr opcode nominal_opcode_from_data(
const data_chunk& data) NOEXCEPT;

/// Categories of opcodes.
Expand Down
34 changes: 17 additions & 17 deletions include/bitcoin/system/chain/script.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,23 @@ class BC_API script

/// Determine if the flag is enabled in the active flags set.
static constexpr bool is_enabled(uint32_t active_flags, flags flag) NOEXCEPT;
static VCONSTEXPR bool is_push_only_pattern(const operations& ops) NOEXCEPT;
static VCONSTEXPR bool is_relaxed_push_pattern(const operations& ops) NOEXCEPT;
static VCONSTEXPR bool is_commitment_pattern(const operations& ops) NOEXCEPT;
static VCONSTEXPR bool is_witness_program_pattern(const operations& ops) NOEXCEPT;
static VCONSTEXPR bool is_pay_null_data_pattern(const operations& ops) NOEXCEPT;
static VCONSTEXPR bool is_pay_op_return_pattern(const operations& ops) NOEXCEPT;
static VCONSTEXPR bool is_pay_multisig_pattern(const operations& ops) NOEXCEPT;
static VCONSTEXPR bool is_pay_public_key_pattern(const operations& ops) NOEXCEPT;
static VCONSTEXPR bool is_pay_key_hash_pattern(const operations& ops) NOEXCEPT;
static VCONSTEXPR bool is_pay_script_hash_pattern(const operations& ops) NOEXCEPT;
static VCONSTEXPR bool is_pay_witness_pattern(const operations& ops) NOEXCEPT;
static VCONSTEXPR bool is_pay_witness_key_hash_pattern(const operations& ops) NOEXCEPT;
static VCONSTEXPR bool is_pay_witness_script_hash_pattern(const operations& ops) NOEXCEPT;
static VCONSTEXPR bool is_sign_multisig_pattern(const operations& ops) NOEXCEPT;
static VCONSTEXPR bool is_sign_public_key_pattern(const operations& ops) NOEXCEPT;
static VCONSTEXPR bool is_sign_key_hash_pattern(const operations& ops) NOEXCEPT;
static VCONSTEXPR bool is_sign_script_hash_pattern(const operations& ops) NOEXCEPT;
static constexpr bool is_push_only_pattern(const operations& ops) NOEXCEPT;
static constexpr bool is_relaxed_push_pattern(const operations& ops) NOEXCEPT;
static constexpr bool is_commitment_pattern(const operations& ops) NOEXCEPT;
static constexpr bool is_witness_program_pattern(const operations& ops) NOEXCEPT;
static constexpr bool is_pay_null_data_pattern(const operations& ops) NOEXCEPT;
static constexpr bool is_pay_op_return_pattern(const operations& ops) NOEXCEPT;
static constexpr bool is_pay_multisig_pattern(const operations& ops) NOEXCEPT;
static constexpr bool is_pay_public_key_pattern(const operations& ops) NOEXCEPT;
static constexpr bool is_pay_key_hash_pattern(const operations& ops) NOEXCEPT;
static constexpr bool is_pay_script_hash_pattern(const operations& ops) NOEXCEPT;
static constexpr bool is_pay_witness_pattern(const operations& ops) NOEXCEPT;
static constexpr bool is_pay_witness_key_hash_pattern(const operations& ops) NOEXCEPT;
static constexpr bool is_pay_witness_script_hash_pattern(const operations& ops) NOEXCEPT;
static constexpr bool is_sign_multisig_pattern(const operations& ops) NOEXCEPT;
static constexpr bool is_sign_public_key_pattern(const operations& ops) NOEXCEPT;
static constexpr bool is_sign_key_hash_pattern(const operations& ops) NOEXCEPT;
static constexpr bool is_sign_script_hash_pattern(const operations& ops) NOEXCEPT;
static bool is_coinbase_pattern(const operations& ops, size_t height) NOEXCEPT;

static inline operations to_pay_null_data_pattern(
Expand Down
4 changes: 2 additions & 2 deletions include/bitcoin/system/chain/witness.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class BC_API witness
/// Skip a witness (as if deserialized).
static void skip(reader& source, bool prefix) NOEXCEPT;

static VCONSTEXPR bool is_push_size(const chunk_cptrs& stack) NOEXCEPT
static constexpr bool is_push_size(const chunk_cptrs& stack) NOEXCEPT
{
return std::all_of(stack.begin(), stack.end(),
[](const auto& element) NOEXCEPT
Expand All @@ -108,7 +108,7 @@ class BC_API witness
}

/// The (only) coinbase witness must be (arbitrary) 32-byte value (bip141).
static VCONSTEXPR bool is_reserved_pattern(const chunk_cptrs& stack) NOEXCEPT
static constexpr bool is_reserved_pattern(const chunk_cptrs& stack) NOEXCEPT
{
return is_one(stack.size()) && stack.front()->size() == hash_size;
}
Expand Down
6 changes: 3 additions & 3 deletions include/bitcoin/system/data/data_reference.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ class data_reference
constexpr data_reference(const data_slice& data) NOEXCEPT;

/// std::string constructor (casts char to uint8_t).
SCONSTEXPR data_reference(const std::string& text) NOEXCEPT;
constexpr data_reference(const std::string& text) NOEXCEPT;

/// data_chunk constructor.
VCONSTEXPR data_reference(const data_chunk& data) NOEXCEPT;
constexpr data_reference(const data_chunk& data) NOEXCEPT;

/// data_array constructor.
template <size_type Size>
Expand All @@ -73,7 +73,7 @@ class data_reference

/// Byte vector constructor (casts Byte to uint8_t).
template <typename Byte, if_one_byte<Byte> = true>
VCONSTEXPR data_reference(const std_vector<Byte>& data) NOEXCEPT;
constexpr data_reference(const std_vector<Byte>& data) NOEXCEPT;

/// Byte iterators constructor (casts to uint8_t).
template <typename Iterator>
Expand Down
10 changes: 5 additions & 5 deletions include/bitcoin/system/data/data_slab.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class data_slab
// TODO: test.
/// Byte vector constructor (casts Byte to uint8_t).
template <typename Byte, if_one_byte<Byte> = true>
VCONSTEXPR data_slab(std_vector<Byte>& data) NOEXCEPT;
constexpr data_slab(std_vector<Byte>& data) NOEXCEPT;

// TODO: restrict to iterator-to-non-const references.
/// Byte iterators constructor (casts to uint8_t).
Expand All @@ -84,7 +84,7 @@ class data_slab

// TODO: test.
/// String constructor (casts char to uint8_t).
SCONSTEXPR data_slab(std::string& text) NOEXCEPT;
constexpr data_slab(std::string& text) NOEXCEPT;

/// Methods.
/// -----------------------------------------------------------------------
Expand All @@ -98,7 +98,7 @@ class data_slab
inline std_vector<value_type> to_chunk() const NOEXCEPT;

/// Convert data to a string (casts uint8_t to char).
SCONSTEXPR std::string to_string() const NOEXCEPT;
constexpr std::string to_string() const NOEXCEPT;

/// Cast buffer to a data_slice.
constexpr data_slice to_slice() const NOEXCEPT;
Expand All @@ -122,7 +122,7 @@ class data_slab
/// -----------------------------------------------------------------------
////template<size_type Size>
////constexpr operator std_array<value_type, Size>() const NOEXCEPT;
////VCONSTEXPR operator std_vector<value_type>() const NOEXCEPT;
////constexpr operator std_vector<value_type>() const NOEXCEPT;
constexpr operator data_slice() const NOEXCEPT;
constexpr value_type operator[](size_type index) const NOEXCEPT;

Expand All @@ -139,7 +139,7 @@ class data_slab
size_type size) NOEXCEPT;

template <typename Pointer>
static SVCONSTEXPR data_slab from_size_(const Pointer begin,
static constexpr data_slab from_size_(const Pointer begin,
size_type size) NOEXCEPT;

pointer begin_;
Expand Down
12 changes: 6 additions & 6 deletions include/bitcoin/system/data/data_slice.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class data_slice

/// Byte vector constructor (casts Byte to uint8_t).
template <typename Byte, if_one_byte<Byte> = true>
VCONSTEXPR data_slice(const std_vector<Byte>& data) NOEXCEPT;
constexpr data_slice(const std_vector<Byte>& data) NOEXCEPT;

// TODO: restrict to iterator-to-const references.
/// Byte iterators constructor (casts to uint8_t).
Expand All @@ -92,10 +92,10 @@ class data_slice
constexpr data_slice(const Byte* begin, const Byte* end) NOEXCEPT;

/// String constructor (casts char to uint8_t).
SCONSTEXPR data_slice(const std::string& text) NOEXCEPT;
constexpr data_slice(const std::string& text) NOEXCEPT;

/// Byte initializer list constructor.
SVCONSTEXPR data_slice(std::initializer_list<value_type> bytes) NOEXCEPT;
constexpr data_slice(std::initializer_list<value_type> bytes) NOEXCEPT;

/// Methods.
/// -----------------------------------------------------------------------
Expand All @@ -109,7 +109,7 @@ class data_slice
inline std_vector<value_type> to_chunk() const NOEXCEPT;

/// Convert data to a string (casts uint8_t to char).
SCONSTEXPR std::string to_string() const NOEXCEPT;
constexpr std::string to_string() const NOEXCEPT;

/// Resize the slice by decrementing the end pointer.
/// This is the only mutable action that can be taken on the slice.
Expand All @@ -130,7 +130,7 @@ class data_slice
/// -----------------------------------------------------------------------
////template<size_type Size>
////constexpr operator std_array<value_type, Size>() const NOEXCEPT;
////VCONSTEXPR operator std_vector<value_type>() const NOEXCEPT;
////constexpr operator std_vector<value_type>() const NOEXCEPT;
constexpr value_type operator[](size_type index) const NOEXCEPT;

private:
Expand All @@ -149,7 +149,7 @@ class data_slice
Pointer begin, size_type size) NOEXCEPT;

template <typename Pointer>
static SVCONSTEXPR data_slice from_size_(
static constexpr data_slice from_size_(
Pointer begin, size_type size) NOEXCEPT;

pointer begin_;
Expand Down
4 changes: 2 additions & 2 deletions include/bitcoin/system/data/exclusive_slice.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ class exclusive_slice
{
}

SCONSTEXPR exclusive_slice(const std::string& text) NOEXCEPT
constexpr exclusive_slice(const std::string& text) NOEXCEPT
: data_slice(text)
{
}

SVCONSTEXPR exclusive_slice(std::initializer_list<value_type> bytes) NOEXCEPT
constexpr exclusive_slice(std::initializer_list<value_type> bytes) NOEXCEPT
: data_slice(bytes.begin(), bytes.end())
{
}
Expand Down
2 changes: 1 addition & 1 deletion include/bitcoin/system/data/string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace system {
/// Casts bytes directly into the string member.
/// to_string(to_chunk(string)) == string.
/// to_string(to_array(string)) == string.
SCONSTEXPR std::string to_string(const data_slice& bytes) NOEXCEPT
constexpr std::string to_string(const data_slice& bytes) NOEXCEPT
{
return bytes.to_string();
}
Expand Down
4 changes: 2 additions & 2 deletions include/bitcoin/system/endian/integers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ constexpr Integer from_big_array(size_t length,
const data_array<Size>& data) NOEXCEPT;

template <typename Integer, if_integer<Integer> = true>
VCONSTEXPR Integer from_big_chunk(size_t length,
constexpr Integer from_big_chunk(size_t length,
const data_chunk& data) NOEXCEPT;

/// Native endianness integer from little-endian data.
Expand All @@ -65,7 +65,7 @@ constexpr Integer from_little_array(size_t length,
const data_array<Size>& data) NOEXCEPT;

template <typename Integer, if_integer<Integer> = true>
VCONSTEXPR Integer from_little_chunk(size_t length,
constexpr Integer from_little_chunk(size_t length,
const data_chunk& data) NOEXCEPT;

} // namespace system
Expand Down
4 changes: 2 additions & 2 deletions include/bitcoin/system/endian/nominal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ constexpr Integral from_little_endian(const data_array<Size>& data) NOEXCEPT;

template <typename Integral,
if_integral_integer<Integral> = true>
VCONSTEXPR Integral from_big_endian(const data_chunk& data) NOEXCEPT;
constexpr Integral from_big_endian(const data_chunk& data) NOEXCEPT;

template <typename Integral,
if_integral_integer<Integral> = true>
VCONSTEXPR Integral from_little_endian(const data_chunk& data) NOEXCEPT;
constexpr Integral from_little_endian(const data_chunk& data) NOEXCEPT;

} // namespace system
} // namespace libbitcoin
Expand Down
4 changes: 2 additions & 2 deletions include/bitcoin/system/endian/uintx_t.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ constexpr uintx_t<to_bits(Size)> uintx_from_little_endian_array(
const data_array<Size>& data) NOEXCEPT;

template <size_t Size>
VCONSTEXPR uintx_t<to_bits(Size)> uintx_from_big_endian_chunk(
constexpr uintx_t<to_bits(Size)> uintx_from_big_endian_chunk(
const data_chunk& data) NOEXCEPT;

template <size_t Size>
VCONSTEXPR uintx_t<to_bits(Size)> uintx_from_little_endian_chunk(
constexpr uintx_t<to_bits(Size)> uintx_from_little_endian_chunk(
const data_chunk& data) NOEXCEPT;

} // namespace system
Expand Down
6 changes: 3 additions & 3 deletions include/bitcoin/system/hash/sha/algorithm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ class algorithm

/// Merkle hashing (sha256/512).
/// -----------------------------------------------------------------------
static VCONSTEXPR digests_t& merkle_hash(digests_t& digests) NOEXCEPT;
static VCONSTEXPR digest_t merkle_root(digests_t&& digests) NOEXCEPT;
static constexpr digests_t& merkle_hash(digests_t& digests) NOEXCEPT;
static constexpr digest_t merkle_root(digests_t&& digests) NOEXCEPT;

protected:
/// Intrinsics constants.
Expand Down Expand Up @@ -341,7 +341,7 @@ class algorithm
INLINE static void merkle_hash_vector(idigests_t& digests,
iblocks_t& blocks) NOEXCEPT;
INLINE static void merkle_hash_vector(digests_t& digests) NOEXCEPT;
VCONSTEXPR static void merkle_hash_(digests_t& digests,
constexpr static void merkle_hash_(digests_t& digests,
size_t offset=zero) NOEXCEPT;

/// sigma0 vectorization (single blocks).
Expand Down
12 changes: 0 additions & 12 deletions include/bitcoin/system/have.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,30 +189,18 @@
#if defined(HAVE_CPP20)
// All versions.
#if defined(HAVE_MSC)
#define HAVE_RANGES
#define HAVE_CONSTEVAL
#define HAVE_STRING_CONSTEXPR
#define HAVE_VECTOR_CONSTEXPR
#elif defined(HAVE_CLANG)
// Apple clang version 15
#if defined(HAVE_APPLE)
#define HAVE_RANGES
#define HAVE_CONSTEVAL
#define HAVE_STRING_CONSTEXPR
#define HAVE_VECTOR_CONSTEXPR
// Ubuntu clang version 16
#else
#define HAVE_RANGES
////#define HAVE_CONSTEVAL (v17)
#define HAVE_STRING_CONSTEXPR
#define HAVE_VECTOR_CONSTEXPR
#endif
// gcc version 12
#elif defined(HAVE_GCC)
#define HAVE_RANGES
#define HAVE_CONSTEVAL
#define HAVE_STRING_CONSTEXPR
#define HAVE_VECTOR_CONSTEXPR
#endif
#endif

Expand Down
4 changes: 2 additions & 2 deletions include/bitcoin/system/impl/chain/operation.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ constexpr opcode operation::opcode_from_positive(uint8_t value) NOEXCEPT

// Compute the minimal data opcode for a given chunk of data.
// Caller should clear data if converting to non-payload opcode.
VCONSTEXPR opcode operation::minimal_opcode_from_data(
constexpr opcode operation::minimal_opcode_from_data(
const data_chunk& data) NOEXCEPT
{
const auto size = data.size();
Expand All @@ -123,7 +123,7 @@ VCONSTEXPR opcode operation::minimal_opcode_from_data(

// Compute the nominal data opcode for a given chunk of data.
// Restricted to sized data, avoids conversion to numeric opcodes.
VCONSTEXPR opcode operation::nominal_opcode_from_data(
constexpr opcode operation::nominal_opcode_from_data(
const data_chunk& data) NOEXCEPT
{
return opcode_from_size(data.size());
Expand Down
Loading

0 comments on commit a31f722

Please sign in to comment.