From 99803085d431de18d7d5467c49982701be1da1fd Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Thu, 29 Jan 2026 17:02:40 -0800 Subject: [PATCH] Start phasing out const_check --- include/fmt/base.h | 15 +++++---------- include/fmt/format.h | 5 +++++ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/fmt/base.h b/include/fmt/base.h index 174bcba2..8540f3d3 100644 --- a/include/fmt/base.h +++ b/include/fmt/base.h @@ -377,11 +377,6 @@ constexpr auto is_constant_evaluated(bool default_value = false) noexcept #endif } -// Suppresses "conditional expression is constant" warnings. -template FMT_ALWAYS_INLINE constexpr auto const_check(T val) -> T { - return val; -} - #ifdef FMT_ASSERT // Use the provided definition. #elif defined(NDEBUG) @@ -1299,7 +1294,7 @@ constexpr auto to_ascii(Char c) -> char { // Returns the number of code units in a code point or 1 on error. template FMT_CONSTEXPR auto code_point_length(const Char* begin) -> int { - if (const_check(sizeof(Char) != 1)) return 1; + if FMT_CONSTEXPR20 (sizeof(Char) != 1) return 1; auto c = static_cast(*begin); return static_cast((0x3a55000000000000ull >> (2 * (c >> 3))) & 3) + 1; } @@ -2394,7 +2389,7 @@ template struct native_formatter { FMT_CONSTEXPR auto parse(parse_context& ctx) -> const Char* { if (ctx.begin() == ctx.end() || *ctx.begin() == '}') return ctx.begin(); auto end = parse_format_specs(ctx.begin(), ctx.end(), specs_, ctx, TYPE); - if (const_check(TYPE == type::char_type)) check_char_specs(specs_); + if FMT_CONSTEXPR20 (TYPE == type::char_type) check_char_specs(specs_); return end; } @@ -2934,7 +2929,7 @@ FMT_API void vprint_buffered(FILE* f, string_view fmt, format_args args); template FMT_INLINE void print(format_string fmt, T&&... args) { vargs va = {{args...}}; - if (detail::const_check(!detail::use_utf8)) + if FMT_CONSTEXPR20 (!detail::use_utf8) return detail::vprint_mojibake(stdout, fmt.str, va, false); return detail::is_locking() ? vprint_buffered(stdout, fmt.str, va) : vprint(fmt.str, va); @@ -2951,7 +2946,7 @@ FMT_INLINE void print(format_string fmt, T&&... args) { template FMT_INLINE void print(FILE* f, format_string fmt, T&&... args) { vargs va = {{args...}}; - if (detail::const_check(!detail::use_utf8)) + if FMT_CONSTEXPR20 (!detail::use_utf8) return detail::vprint_mojibake(f, fmt.str, va, false); return detail::is_locking() ? vprint_buffered(f, fmt.str, va) : vprint(f, fmt.str, va); @@ -2962,7 +2957,7 @@ FMT_INLINE void print(FILE* f, format_string fmt, T&&... args) { template FMT_INLINE void println(FILE* f, format_string fmt, T&&... args) { vargs va = {{args...}}; - if (detail::const_check(detail::use_utf8)) return vprintln(f, fmt.str, va); + if FMT_CONSTEXPR20 (detail::use_utf8) return vprintln(f, fmt.str, va); detail::vprint_mojibake(f, fmt.str, va, true); } diff --git a/include/fmt/format.h b/include/fmt/format.h index 93d5965f..0e2339d1 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -248,6 +248,11 @@ inline auto clzll(uint64_t x) -> int { # define FMT_BUILTIN_CLZLL(n) detail::clzll(n) #endif // FMT_MSC_VERSION && !defined(FMT_BUILTIN_CLZLL) +// Suppresses "conditional expression is constant" warnings. +template FMT_ALWAYS_INLINE constexpr auto const_check(T val) -> T { + return val; +} + FMT_CONSTEXPR inline void abort_fuzzing_if(bool condition) { ignore_unused(condition); #ifdef FMT_FUZZ