From 8d5f9d6d40797eb57fe97e3ee12c0036655078b3 Mon Sep 17 00:00:00 2001 From: dbj Date: Wed, 13 Nov 2019 07:42:03 +0100 Subject: [PATCH] FMT_FAST_FAIL added [[noreturn]] -- where possible why is do_throw() used only for MSVC builds? using fmt::terror for when FTM_THROW was assert(false) before ... --- include/fmt/format.h | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index 9c104df1..207428d4 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -70,29 +70,46 @@ #else # define FMT_HAS_BUILTIN(x) 0 #endif +FMT_BEGIN_NAMESPACE +// terror == terminating error +[[noreturn]] inline void terror(const char msg_[BUFSIZ]) { + ::puts("\n\n\nFast exit on {fmt} error with message: "); + ::puts(msg_); + ::perror("\nPOSIX error message: "); + std::exit(EXIT_FAILURE); +} +FMT_END_NAMESPACE #ifndef FMT_THROW # if FMT_EXCEPTIONS # if FMT_MSC_VER +//TODO: why is this only for MSVC builds? FMT_BEGIN_NAMESPACE namespace internal { +#define FMT_FAST_FAIL 1 /*TODO: remove before relase, here for testing purposes */ +#if FMT_FAST_FAIL + template [[noreturn]] inline void do_throw(const Exception& x) { + terror(x.what()); + } +#else template inline void do_throw(const Exception& x) { // Silence unreachable code warnings in MSVC because these are nearly // impossible to fix in a generic code. volatile bool b = true; if (b) throw x; } +#endif } // namespace internal FMT_END_NAMESPACE -# define FMT_THROW(x) fmt::internal::do_throw(x) +//TODO: why is do_throw() only for MSVC builds? +# define FMT_THROW(x) fmt :: internal::do_throw(x) # else # define FMT_THROW(x) throw x # endif # else -# define FMT_THROW(x) \ - do { \ - static_cast(sizeof(x)); \ - assert(false); \ +# define FMT_THROW(x) \ + do { \ + fmt :: terror(x.what()) \ } while (false) # endif #endif