diff --git a/include/fmt/format.h b/include/fmt/format.h index afcba52ed043e..846f80bf8701a 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -991,8 +991,12 @@ FMT_CONSTEXPR20 inline auto count_digits(uint64_t n) -> int { template FMT_CONSTEXPR auto count_digits(UInt n) -> int { #ifdef FMT_BUILTIN_CLZ - if (num_bits() == 32) - return (FMT_BUILTIN_CLZ(static_cast(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() == 32) + return [](UInt m) { + return (FMT_BUILTIN_CLZ(static_cast(m) | 1) ^ 31) / BITS + 1; + }(n); #endif // Lambda avoids unreachable code warnings from NVHPC. return [](UInt m) {