mirror of
https://github.com/fmtlib/fmt.git
synced 2026-07-30 16:26:27 +08:00
Suppress MSVC C4702 header-wide instead of restructuring code
Revert the explicit-else workaround from #4822 and instead disable the "unreachable code" warning for all of base.h. Add an FMT_PRAGMA_MSVC helper (mirroring FMT_PRAGMA_GCC/CLANG) and wrap the header in a single warning(push)/disable:4702/pop pair, keeping the original control flow.
This commit is contained in:
parent
b54093c658
commit
cd67635a19
@ -223,6 +223,11 @@
|
||||
#else
|
||||
# define FMT_PRAGMA_CLANG(x)
|
||||
#endif
|
||||
#if FMT_MSC_VERSION
|
||||
# define FMT_PRAGMA_MSVC(x) __pragma(x)
|
||||
#else
|
||||
# define FMT_PRAGMA_MSVC(x)
|
||||
#endif
|
||||
|
||||
#ifndef FMT_USE_OPTIMIZE_PRAGMA
|
||||
# define FMT_USE_OPTIMIZE_PRAGMA 1
|
||||
@ -235,6 +240,9 @@ FMT_PRAGMA_GCC(push_options)
|
||||
FMT_PRAGMA_GCC(optimize("Og"))
|
||||
#endif
|
||||
|
||||
FMT_PRAGMA_MSVC(warning(push))
|
||||
FMT_PRAGMA_MSVC(warning(disable : 4702))
|
||||
|
||||
#ifdef FMT_DEPRECATED
|
||||
// Use the provided definition.
|
||||
#elif FMT_HAS_CPP14_ATTRIBUTE(deprecated)
|
||||
@ -1285,12 +1293,9 @@ constexpr auto to_ascii(Char c) -> char {
|
||||
// Returns the number of code units in a code point or 1 on error.
|
||||
template <typename Char>
|
||||
FMT_CONSTEXPR auto code_point_length(const Char* begin) -> int {
|
||||
if FMT_CONSTEXPR20 (sizeof(Char) != 1) {
|
||||
return 1;
|
||||
} else {
|
||||
if FMT_CONSTEXPR20 (sizeof(Char) != 1) return 1;
|
||||
auto c = static_cast<unsigned char>(*begin);
|
||||
return static_cast<int>((0x3a55000000000000ull >> (2 * (c >> 3))) & 3) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Parses the range [begin, end) as an unsigned integer. This function assumes
|
||||
@ -2899,12 +2904,10 @@ 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 FMT_CONSTEXPR20 (!detail::use_utf8) {
|
||||
detail::vprint_mojibake(stdout, fmt.str, va, false);
|
||||
} else {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2918,12 +2921,10 @@ 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 FMT_CONSTEXPR20 (!detail::use_utf8) {
|
||||
detail::vprint_mojibake(f, fmt.str, va, false);
|
||||
} else {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/// Formats `args` according to specifications in `fmt` and writes the output
|
||||
@ -2931,11 +2932,8 @@ 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...}};
|
||||
if FMT_CONSTEXPR20 (detail::use_utf8) {
|
||||
vprintln(f, fmt.str, va);
|
||||
} else {
|
||||
if FMT_CONSTEXPR20 (detail::use_utf8) return vprintln(f, fmt.str, va);
|
||||
detail::vprint_mojibake(f, fmt.str, va, true);
|
||||
}
|
||||
}
|
||||
|
||||
/// Formats `args` according to specifications in `fmt` and writes the output
|
||||
@ -2946,6 +2944,7 @@ FMT_INLINE void println(format_string<T...> fmt, T&&... args) {
|
||||
}
|
||||
|
||||
FMT_PRAGMA_GCC(pop_options)
|
||||
FMT_PRAGMA_MSVC(warning(pop))
|
||||
FMT_END_EXPORT
|
||||
FMT_END_NAMESPACE
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user