Skip to content

Commit

Permalink
Workaround to MSVC (Issue fmtlib#2761)
Browse files Browse the repository at this point in the history
  • Loading branch information
phprus committed Feb 13, 2022
1 parent a44716f commit 98238cd
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -991,8 +991,12 @@ FMT_CONSTEXPR20 inline auto count_digits(uint64_t n) -> int {
template <int BITS, typename UInt>
FMT_CONSTEXPR auto count_digits(UInt n) -> int {
#ifdef FMT_BUILTIN_CLZ
if (num_bits<UInt>() == 32)
return (FMT_BUILTIN_CLZ(static_cast<uint32_t>(n) | 1) ^ 31) / BITS + 1;
// Lambda avoids error: failure was caused by call of undefined function or
// one not declared 'constexpr' from MSVC.
if (!is_constant_evaluated() && num_bits<UInt>() == 32)
return [](UInt m) {
return (FMT_BUILTIN_CLZ(static_cast<uint32_t>(m) | 1) ^ 31) / BITS + 1;
}(n);
#endif
// Lambda avoids unreachable code warnings from NVHPC.
return [](UInt m) {
Expand Down

0 comments on commit 98238cd

Please sign in to comment.