From 542600013f346f03417ae4e0f1b8dc64df5da3d2 Mon Sep 17 00:00:00 2001 From: Vladislav Shchapov Date: Sat, 9 Nov 2024 20:43:46 +0500 Subject: [PATCH] Suppress MSVC warnings "C4127: conditional expression is constant" by used const_check (#4233) Signed-off-by: Vladislav Shchapov --- include/fmt/base.h | 10 ++++++---- include/fmt/format.h | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/include/fmt/base.h b/include/fmt/base.h index 2700e631..9bd09fce 100644 --- a/include/fmt/base.h +++ b/include/fmt/base.h @@ -2885,7 +2885,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::use_utf8) + if (detail::const_check(!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); @@ -2902,7 +2902,8 @@ 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::use_utf8) return detail::vprint_mojibake(f, fmt.str, va, false); + if (detail::const_check(!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); } @@ -2912,8 +2913,9 @@ 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...}}; - return detail::use_utf8 ? vprintln(f, fmt.str, va) - : detail::vprint_mojibake(f, fmt.str, va, true); + return detail::const_check(detail::use_utf8) + ? vprintln(f, fmt.str, va) + : detail::vprint_mojibake(f, fmt.str, va, true); } /// Formats `args` according to specifications in `fmt` and writes the output diff --git a/include/fmt/format.h b/include/fmt/format.h index b34fd2ae..62db5a0d 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -1695,7 +1695,7 @@ FMT_API auto is_printable(uint32_t cp) -> bool; inline auto needs_escape(uint32_t cp) -> bool { if (cp < 0x20 || cp == 0x7f || cp == '"' || cp == '\\') return true; - if (FMT_OPTIMIZE_SIZE > 1) return false; + if (const_check(FMT_OPTIMIZE_SIZE > 1)) return false; return !is_printable(cp); } @@ -1718,7 +1718,7 @@ auto find_escape(const Char* begin, const Char* end) inline auto find_escape(const char* begin, const char* end) -> find_escape_result { - if (!use_utf8) return find_escape(begin, end); + if (const_check(!use_utf8)) return find_escape(begin, end); auto result = find_escape_result{end, nullptr, 0}; for_each_codepoint(string_view(begin, to_unsigned(end - begin)), [&](uint32_t cp, string_view sv) {