Avoid MSVC C4702 unreachable code warning in print/println

When `detail::use_utf8` is a compile-time constant, the `if
FMT_CONSTEXPR20` branch in `print` and `println` always returns,
leaving the trailing statement unreachable. Under C++20 this is an
`if constexpr`, so MSVC reports the dead statement as warning C4702
at high warning levels (e.g. /Wall).

Move the fallthrough into an `else` branch so it becomes part of the
discarded `if constexpr` branch, which MSVC does not flag. The
behavior is unchanged.

Closes #4810

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Nathan DeMoss 2026-06-17 12:20:22 -04:00 committed by Victor Zverovich
parent d24fef27d1
commit 260abdbed7

View File

@ -2898,8 +2898,9 @@ FMT_INLINE void print(format_string<T...> fmt, T&&... args) {
vargs<T...> va = {{args...}};
if FMT_CONSTEXPR20 (!detail::use_utf8)
return detail::vprint_mojibake(stdout, fmt.str, va, false);
detail::is_locking<T...>() ? vprint_buffered(stdout, fmt.str, va)
: vprint(fmt.str, va);
else
detail::is_locking<T...>() ? vprint_buffered(stdout, fmt.str, va)
: vprint(fmt.str, va);
}
/**
@ -2915,8 +2916,9 @@ FMT_INLINE void print(FILE* f, format_string<T...> fmt, T&&... args) {
vargs<T...> va = {{args...}};
if FMT_CONSTEXPR20 (!detail::use_utf8)
return detail::vprint_mojibake(f, fmt.str, va, false);
detail::is_locking<T...>() ? vprint_buffered(f, fmt.str, va)
: vprint(f, fmt.str, va);
else
detail::is_locking<T...>() ? vprint_buffered(f, fmt.str, va)
: vprint(f, fmt.str, va);
}
/// Formats `args` according to specifications in `fmt` and writes the output
@ -2925,7 +2927,7 @@ template <typename... T>
FMT_INLINE void println(FILE* f, format_string<T...> fmt, T&&... args) {
vargs<T...> va = {{args...}};
if FMT_CONSTEXPR20 (detail::use_utf8) return vprintln(f, fmt.str, va);
detail::vprint_mojibake(f, fmt.str, va, true);
else detail::vprint_mojibake(f, fmt.str, va, true);
}
/// Formats `args` according to specifications in `fmt` and writes the output