Skip to content

Commit 6804429

Browse files
committed
Disable usage of long double in static_assert with clang
Signed-off-by: Ian <[email protected]>
1 parent f49b868 commit 6804429

File tree

5 files changed

+14
-26
lines changed

5 files changed

+14
-26
lines changed

include/ccmath/internal/support/bits.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace ccm::support
3030
{
3131

3232
template <typename To, typename From>
33-
inline constexpr std::enable_if_t<
33+
constexpr std::enable_if_t<
3434
sizeof(To) == sizeof(From) && std::is_trivially_constructible_v<To> && std::is_trivially_copyable_v<To> && std::is_trivially_copyable_v<From>, To>
3535
bit_cast(const From & from)
3636
{

include/ccmath/internal/support/fp/fp_bits.hpp

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ namespace ccm::support::fp
3232
/// All supported floating point types
3333
enum class FPType : std::uint8_t
3434
{
35-
eBinary16, // TODO: Currently don't handle float16 but might in the future
3635
eBinary32,
3736
eBinary64,
3837
eBinary80,
@@ -49,16 +48,6 @@ namespace ccm::support::fp
4948
{
5049
};
5150

52-
template <>
53-
struct FPLayout<FPType::eBinary16>
54-
{
55-
using storage_type = std::uint16_t;
56-
static constexpr std::int_fast32_t sign_length = 1;
57-
static constexpr std::int_fast32_t exponent_length = 5;
58-
static constexpr std::int_fast32_t significand_length = 10;
59-
static constexpr std::int_fast32_t fraction_length = significand_length;
60-
};
61-
6251
template <>
6352
struct FPLayout<FPType::eBinary32>
6453
{
@@ -827,9 +816,6 @@ namespace ccm::support::fp
827816
else if constexpr (LDBL_MANT_DIG == 64) { return FPType::eBinary80; } // long double is 80-bits
828817
else if constexpr (LDBL_MANT_DIG == 113) { return FPType::eBinary128; } // long double is 128-bits
829818
}
830-
#if defined(CCM_TYPES_HAS_FLOAT128)
831-
else if constexpr (std::is_same_v<UnqualT, types::float128>) { return FPType::eBinary128; }
832-
#endif
833819
else { static_assert(support::always_false<UnqualT>, "Unsupported type"); }
834820
return FPType::eBinary32; // This will never be reached due to assert. Only here to appease the compiler.
835821
}
@@ -841,7 +827,7 @@ namespace ccm::support::fp
841827
template <typename T>
842828
struct FPBits final : internal::FPRepImpl<get_fp_type<T>(), FPBits<T>>
843829
{
844-
static_assert(std::is_floating_point_v<T>, "FPBits instantiated with invalid type.");
830+
static_assert(support::traits::ccm_is_floating_point_v<T>, "FPBits instantiated with invalid type.");
845831
using BASE = internal::FPRepImpl<get_fp_type<T>(), FPBits<T>>;
846832
using storage_type = typename BASE::storage_type;
847833

@@ -850,7 +836,7 @@ namespace ccm::support::fp
850836
template <typename XType>
851837
inline constexpr explicit FPBits(XType x)
852838
{
853-
using UnQual = std::remove_cv_t<XType>;
839+
using UnQual = typename std::remove_cv_t<XType>;
854840
if constexpr (std::is_same_v<UnQual, T>) { BASE::bits = support::bit_cast<storage_type>(x); }
855841
else if constexpr (std::is_same_v<UnQual, storage_type>) { BASE::bits = x; }
856842
else

include/ccmath/internal/types/big_int.hpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,7 @@ namespace ccm::types
194194
}
195195
#endif
196196
#ifdef CCM_TYPES_HAS_INT128
197-
else if constexpr (std::is_same_v<word, std::uint64_t>)
198-
{
199-
return split<__uint128_t>(static_cast<__uint128_t>(lhs) * static_cast<__uint128_t>(rhs));
200-
}
197+
else if constexpr (std::is_same_v<word, std::uint64_t>) { return split<__uint128_t>(__uint128_t(lhs) * __uint128_t(rhs)); }
201198
#endif
202199
else
203200
{
@@ -725,7 +722,7 @@ namespace ccm::types
725722
*/
726723
[[nodiscard]] constexpr bool is_neg() const { return SIGNED && get_msb(); }
727724

728-
template <size_t OtherBits, bool OtherSigned, typename OtherWordType>
725+
template <std::size_t OtherBits, bool OtherSigned, typename OtherWordType>
729726
constexpr explicit operator BigInt<OtherBits, OtherSigned, OtherWordType>() const
730727
{
731728
return BigInt<OtherBits, OtherSigned, OtherWordType>(this);
@@ -1491,7 +1488,7 @@ namespace ccm::support
14911488
(sizeof(To) == sizeof(From)) && std::is_trivially_copyable_v<To> && std::is_trivially_copyable_v<From> && types::is_big_int<To>::value, To>
14921489
bit_cast(const From & from)
14931490
{
1494-
To out;
1491+
To out{};
14951492
using Storage = decltype(out.val);
14961493
out.val = support::bit_cast<Storage>(from);
14971494
return out;

include/ccmath/internal/types/int128_types.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212

1313
#include "ccmath/internal/config/type_support.hpp"
1414

15-
#ifndef CCM_TYPES_HAS_INT128
16-
#include "ccmath/internal/types/big_int.hpp"
17-
#endif
15+
#include "ccmath/internal/types/big_int.hpp"
1816

1917
namespace ccm::types
2018
{

test/fmanip/ldexp_test.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,14 @@ TYPED_TEST_SUITE(CcmathFmanipTests, TestTypes);
2626

2727
TYPED_TEST(CcmathFmanipTests, LdexpStaticAssert)
2828
{
29+
#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.
30+
if constexpr (!std::is_same_v<long double, TypeParam>)
31+
{
32+
static_assert(ccm::ldexp(static_cast<TypeParam>(1.0), 0) == ccm::ldexp(static_cast<TypeParam>(1.0), 0));
33+
}
34+
#else
2935
static_assert(ccm::ldexp(static_cast<TypeParam>(1.0), 0) == ccm::ldexp(static_cast<TypeParam>(1.0), 0));
36+
#endif
3037
}
3138

3239
TYPED_TEST(CcmathFmanipTests, LdexpBasic)

0 commit comments

Comments
 (0)