From 6804429232a8b7abebaec663900f6ca3c8a6e7ee Mon Sep 17 00:00:00 2001 From: Ian Date: Sun, 12 Jan 2025 22:26:36 -0500 Subject: [PATCH] Disable usage of long double in static_assert with clang Signed-off-by: Ian --- include/ccmath/internal/support/bits.hpp | 2 +- include/ccmath/internal/support/fp/fp_bits.hpp | 18 ++---------------- include/ccmath/internal/types/big_int.hpp | 9 +++------ include/ccmath/internal/types/int128_types.hpp | 4 +--- test/fmanip/ldexp_test.cpp | 7 +++++++ 5 files changed, 14 insertions(+), 26 deletions(-) diff --git a/include/ccmath/internal/support/bits.hpp b/include/ccmath/internal/support/bits.hpp index 8972e7d3..3cf8039a 100644 --- a/include/ccmath/internal/support/bits.hpp +++ b/include/ccmath/internal/support/bits.hpp @@ -30,7 +30,7 @@ namespace ccm::support { template - inline constexpr std::enable_if_t< + constexpr std::enable_if_t< sizeof(To) == sizeof(From) && std::is_trivially_constructible_v && std::is_trivially_copyable_v && std::is_trivially_copyable_v, To> bit_cast(const From & from) { diff --git a/include/ccmath/internal/support/fp/fp_bits.hpp b/include/ccmath/internal/support/fp/fp_bits.hpp index fc666c84..fccecf60 100644 --- a/include/ccmath/internal/support/fp/fp_bits.hpp +++ b/include/ccmath/internal/support/fp/fp_bits.hpp @@ -32,7 +32,6 @@ namespace ccm::support::fp /// All supported floating point types enum class FPType : std::uint8_t { - eBinary16, // TODO: Currently don't handle float16 but might in the future eBinary32, eBinary64, eBinary80, @@ -49,16 +48,6 @@ namespace ccm::support::fp { }; - template <> - struct FPLayout - { - using storage_type = std::uint16_t; - static constexpr std::int_fast32_t sign_length = 1; - static constexpr std::int_fast32_t exponent_length = 5; - static constexpr std::int_fast32_t significand_length = 10; - static constexpr std::int_fast32_t fraction_length = significand_length; - }; - template <> struct FPLayout { @@ -827,9 +816,6 @@ namespace ccm::support::fp else if constexpr (LDBL_MANT_DIG == 64) { return FPType::eBinary80; } // long double is 80-bits else if constexpr (LDBL_MANT_DIG == 113) { return FPType::eBinary128; } // long double is 128-bits } -#if defined(CCM_TYPES_HAS_FLOAT128) - else if constexpr (std::is_same_v) { return FPType::eBinary128; } -#endif else { static_assert(support::always_false, "Unsupported type"); } return FPType::eBinary32; // This will never be reached due to assert. Only here to appease the compiler. } @@ -841,7 +827,7 @@ namespace ccm::support::fp template struct FPBits final : internal::FPRepImpl(), FPBits> { - static_assert(std::is_floating_point_v, "FPBits instantiated with invalid type."); + static_assert(support::traits::ccm_is_floating_point_v, "FPBits instantiated with invalid type."); using BASE = internal::FPRepImpl(), FPBits>; using storage_type = typename BASE::storage_type; @@ -850,7 +836,7 @@ namespace ccm::support::fp template inline constexpr explicit FPBits(XType x) { - using UnQual = std::remove_cv_t; + using UnQual = typename std::remove_cv_t; if constexpr (std::is_same_v) { BASE::bits = support::bit_cast(x); } else if constexpr (std::is_same_v) { BASE::bits = x; } else diff --git a/include/ccmath/internal/types/big_int.hpp b/include/ccmath/internal/types/big_int.hpp index 0ca4fc72..4b61fa93 100644 --- a/include/ccmath/internal/types/big_int.hpp +++ b/include/ccmath/internal/types/big_int.hpp @@ -194,10 +194,7 @@ namespace ccm::types } #endif #ifdef CCM_TYPES_HAS_INT128 - else if constexpr (std::is_same_v) - { - return split<__uint128_t>(static_cast<__uint128_t>(lhs) * static_cast<__uint128_t>(rhs)); - } + else if constexpr (std::is_same_v) { return split<__uint128_t>(__uint128_t(lhs) * __uint128_t(rhs)); } #endif else { @@ -725,7 +722,7 @@ namespace ccm::types */ [[nodiscard]] constexpr bool is_neg() const { return SIGNED && get_msb(); } - template + template constexpr explicit operator BigInt() const { return BigInt(this); @@ -1491,7 +1488,7 @@ namespace ccm::support (sizeof(To) == sizeof(From)) && std::is_trivially_copyable_v && std::is_trivially_copyable_v && types::is_big_int::value, To> bit_cast(const From & from) { - To out; + To out{}; using Storage = decltype(out.val); out.val = support::bit_cast(from); return out; diff --git a/include/ccmath/internal/types/int128_types.hpp b/include/ccmath/internal/types/int128_types.hpp index 1e5d6ea1..ffb2e98b 100644 --- a/include/ccmath/internal/types/int128_types.hpp +++ b/include/ccmath/internal/types/int128_types.hpp @@ -12,9 +12,7 @@ #include "ccmath/internal/config/type_support.hpp" -#ifndef CCM_TYPES_HAS_INT128 - #include "ccmath/internal/types/big_int.hpp" -#endif +#include "ccmath/internal/types/big_int.hpp" namespace ccm::types { diff --git a/test/fmanip/ldexp_test.cpp b/test/fmanip/ldexp_test.cpp index 6922d339..72e45ed9 100644 --- a/test/fmanip/ldexp_test.cpp +++ b/test/fmanip/ldexp_test.cpp @@ -26,7 +26,14 @@ TYPED_TEST_SUITE(CcmathFmanipTests, TestTypes); TYPED_TEST(CcmathFmanipTests, LdexpStaticAssert) { +#if defined(__clang__) // long double does not really work on static_assert for clang. This is due to how __builtin_bit_cast works on clang. + if constexpr (!std::is_same_v) + { + static_assert(ccm::ldexp(static_cast(1.0), 0) == ccm::ldexp(static_cast(1.0), 0)); + } +#else static_assert(ccm::ldexp(static_cast(1.0), 0) == ccm::ldexp(static_cast(1.0), 0)); +#endif } TYPED_TEST(CcmathFmanipTests, LdexpBasic)