diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index aaa3eaef..8f0355b3 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -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 } diff --git a/include/fmt/format.h b/include/fmt/format.h index e5411886..3961ded3 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -165,28 +165,14 @@ template struct iterator_traits> { }; } // namespace std -#ifndef FMT_THROW -# if FMT_USE_EXCEPTIONS -# if FMT_MSC_VERSION || defined(__NVCC__) -FMT_BEGIN_NAMESPACE -namespace detail { -template 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