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 ...
This commit is contained in:
dbj 2019-11-13 07:42:03 +01:00 committed by GitHub
parent 1f918159ed
commit 8d5f9d6d40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -70,29 +70,46 @@
#else #else
# define FMT_HAS_BUILTIN(x) 0 # define FMT_HAS_BUILTIN(x) 0
#endif #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 #ifndef FMT_THROW
# if FMT_EXCEPTIONS # if FMT_EXCEPTIONS
# if FMT_MSC_VER # if FMT_MSC_VER
//TODO: why is this only for MSVC builds?
FMT_BEGIN_NAMESPACE FMT_BEGIN_NAMESPACE
namespace internal { namespace internal {
#define FMT_FAST_FAIL 1 /*TODO: remove before relase, here for testing purposes */
#if FMT_FAST_FAIL
template <typename Exception> [[noreturn]] inline void do_throw(const Exception& x) {
terror(x.what());
}
#else
template <typename Exception> inline void do_throw(const Exception& x) { template <typename Exception> inline void do_throw(const Exception& x) {
// Silence unreachable code warnings in MSVC because these are nearly // Silence unreachable code warnings in MSVC because these are nearly
// impossible to fix in a generic code. // impossible to fix in a generic code.
volatile bool b = true; volatile bool b = true;
if (b) throw x; if (b) throw x;
} }
#endif
} // namespace internal } // namespace internal
FMT_END_NAMESPACE 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 # else
# define FMT_THROW(x) throw x # define FMT_THROW(x) throw x
# endif # endif
# else # else
# define FMT_THROW(x) \ # define FMT_THROW(x) \
do { \ do { \
static_cast<void>(sizeof(x)); \ fmt :: terror(x.what()) \
assert(false); \
} while (false) } while (false)
# endif # endif
#endif #endif