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 } // namespace detail
FMT_FUNC void report_error(const char* message) { 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 #if FMT_USE_EXCEPTIONS
// Use FMT_THROW instead of throw to avoid bogus unreachable code warnings // Use FMT_THROW instead of throw to avoid bogus unreachable code warnings
// from MSVC. // from MSVC.
FMT_THROW(format_error(message)); FMT_THROW(format_error(message));
#else #else
// Silence unreachable code warnings in MSVC. fputs(message, stderr);
volatile bool b = true; abort();
if (b) {
fputs(message, stderr);
abort();
}
#endif #endif
} }

View File

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