Skip to content

Commit bcecb9f

Browse files
committed
Add static assertion for target decimal type
1 parent 112051b commit bcecb9f

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

include/boost/decimal/dpd_conversion.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,9 @@ template <typename DecimalType = decimal32_fast>
426426
constexpr auto from_dpd_d32(std::uint32_t dpd) noexcept
427427
BOOST_DECIMAL_REQUIRES(detail::is_decimal_floating_point_v, DecimalType)
428428
{
429+
static_assert(std::is_same<DecimalType, decimal32>::value || std::is_same<DecimalType, decimal32_fast>::value,
430+
"Target decimal type must be 32-bits");
431+
429432
// First we check for non-finite values
430433
// Since they are in the same initial format as BID it's easy to check with our existing masks
431434
if ((dpd & detail::d32_inf_mask) == detail::d32_inf_mask)
@@ -619,6 +622,9 @@ template <typename DecimalType = decimal64_fast>
619622
constexpr auto from_dpd_d64(std::uint64_t dpd) noexcept
620623
BOOST_DECIMAL_REQUIRES(detail::is_decimal_floating_point_v, DecimalType)
621624
{
625+
static_assert(std::is_same<DecimalType, decimal64>::value || std::is_same<DecimalType, decimal64_fast>::value,
626+
"Target decimal type must be 64-bits");
627+
622628
// First we check for non-finite values
623629
// Since they are in the same initial format as BID it's easy to check with our existing masks
624630
if ((dpd & detail::d64_inf_mask) == detail::d64_inf_mask)

0 commit comments

Comments
 (0)