Skip to content

Commit

Permalink
Suppress MSVC warnings "C4127: conditional expression is constant" by…
Browse files Browse the repository at this point in the history
… used const_check (#4233)

Signed-off-by: Vladislav Shchapov <vladislav@shchapov.ru>
  • Loading branch information
phprus authored Nov 9, 2024
1 parent 720da57 commit 5426000
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions include/fmt/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -2885,7 +2885,7 @@ FMT_API void vprint_buffered(FILE* f, string_view fmt, format_args args);
template <typename... T>
FMT_INLINE void print(format_string<T...> fmt, T&&... args) {
vargs<T...> 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<T...>() ? vprint_buffered(stdout, fmt.str, va)
: vprint(fmt.str, va);
Expand All @@ -2902,7 +2902,8 @@ FMT_INLINE void print(format_string<T...> fmt, T&&... args) {
template <typename... T>
FMT_INLINE void print(FILE* f, format_string<T...> fmt, T&&... args) {
vargs<T...> 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<T...>() ? vprint_buffered(f, fmt.str, va)
: vprint(f, fmt.str, va);
}
Expand All @@ -2912,8 +2913,9 @@ FMT_INLINE void print(FILE* f, format_string<T...> fmt, T&&... args) {
template <typename... T>
FMT_INLINE void println(FILE* f, format_string<T...> fmt, T&&... args) {
vargs<T...> 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
Expand Down
4 changes: 2 additions & 2 deletions include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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<char> {
if (!use_utf8) return find_escape<char>(begin, end);
if (const_check(!use_utf8)) return find_escape<char>(begin, end);
auto result = find_escape_result<char>{end, nullptr, 0};
for_each_codepoint(string_view(begin, to_unsigned(end - begin)),
[&](uint32_t cp, string_view sv) {
Expand Down

0 comments on commit 5426000

Please sign in to comment.