Merge workarounds for bogus MSVC warnings

This commit is contained in:
Victor Zverovich
2025-08-24 08:10:57 -07:00
parent 72c82296d6
commit 61e0503daf
2 changed files with 16 additions and 28 deletions

View File

@@ -133,17 +133,19 @@ FMT_FUNC auto write_loc(appender out, loc_value value,
} // namespace detail
FMT_FUNC void report_error(const char* message) {
#if FMT_MSC_VERSION || defined(__NVCC__)
// Silence unreachable code warnings in MSVC and NVCC because these
// are nearly impossible to fix in a generic code.
volatile bool b = true;
if (!b) return;
#endif
#if FMT_USE_EXCEPTIONS
// Use FMT_THROW instead of throw to avoid bogus unreachable code warnings
// from MSVC.
FMT_THROW(format_error(message));
#else
// Silence unreachable code warnings in MSVC.
volatile bool b = true;
if (b) {
fputs(message, stderr);
abort();
}
fputs(message, stderr);
abort();
#endif
}

View File

@@ -165,28 +165,14 @@ template <typename T> struct iterator_traits<fmt::basic_appender<T>> {
};
} // namespace std
#ifndef FMT_THROW
# if FMT_USE_EXCEPTIONS
# if FMT_MSC_VERSION || defined(__NVCC__)
FMT_BEGIN_NAMESPACE
namespace detail {
template <typename Exception> inline void do_throw(const Exception& x) {
// Silence unreachable code warnings in MSVC and NVCC because these
// are nearly impossible to fix in a generic code.
volatile bool b = true;
if (b) throw x;
}
} // namespace detail
FMT_END_NAMESPACE
# define FMT_THROW(x) detail::do_throw(x)
# else
# define FMT_THROW(x) throw x
# endif
# else
# define FMT_THROW(x) \
::fmt::detail::assert_fail(__FILE__, __LINE__, (x).what())
# endif // FMT_USE_EXCEPTIONS
#endif // FMT_THROW
#ifdef FMT_THROW
// Use the provided definition.
#elif FMT_USE_EXCEPTIONS
# define FMT_THROW(x) throw x
#else
# define FMT_THROW(x) \
::fmt::detail::assert_fail(__FILE__, __LINE__, (x).what())
#endif
// Defining FMT_REDUCE_INT_INSTANTIATIONS to 1, will reduce the number of
// integer formatter template instantiations to just one by only using the