From 593d3aef9e7b837155cf6d9be7cd749f1c2b00b4 Mon Sep 17 00:00:00 2001 From: Carter Li Date: Sat, 14 Mar 2015 14:37:02 +0800 Subject: [PATCH 1/3] Improve behaviors when disabling exceptions --- format.cc | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/format.cc b/format.cc index 865b78cf..828a3644 100644 --- a/format.cc +++ b/format.cc @@ -66,10 +66,24 @@ using fmt::internal::Arg; #ifndef FMT_THROW # if FMT_EXCEPTIONS # define FMT_THROW(x) throw x -# define FMT_RETURN_AFTER_THROW(x) # else -# define FMT_THROW(x) assert(false) -# define FMT_RETURN_AFTER_THROW(x) return x +# ifdef DEBUG +# define FMT_THROW(x) assert(false && #x) +# elif defined _MSC_VER +# define FMT_THROW(x) __assume(0) +# elif defined __clang__ || FMT_GCC_VERSION >= 405 +# define FMT_THROW(x) __builtin_unreachable() +# else +# define FMT_THROW(x) std::abort() +# endif +# endif +#endif + +#ifndef FMT_NORETURN +# if defined __GNUC__ || defined __clang__ +# define FMT_NORETURN __attribute__((__noreturn__)) +# elif defined _MSC_VER +# define FMT_NORETURN __declspec(noreturn) # endif #endif @@ -257,9 +271,9 @@ class WidthHandler : public fmt::internal::ArgVisitor { public: explicit WidthHandler(fmt::FormatSpec &spec) : spec_(spec) {} + FMT_NORETURN unsigned visit_unhandled_arg() { FMT_THROW(fmt::FormatError("width is not integer")); - FMT_RETURN_AFTER_THROW(0); } template @@ -279,9 +293,9 @@ class WidthHandler : public fmt::internal::ArgVisitor { class PrecisionHandler : public fmt::internal::ArgVisitor { public: + FMT_NORETURN unsigned visit_unhandled_arg() { FMT_THROW(fmt::FormatError("precision is not integer")); - FMT_RETURN_AFTER_THROW(0); } template From 2d4631a5804c63a3dc8d2154240aa270619de464 Mon Sep 17 00:00:00 2001 From: Carter Li Date: Sat, 14 Mar 2015 14:54:37 +0800 Subject: [PATCH 2/3] Silence -Wunused-parameter --- format.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/format.cc b/format.cc index 828a3644..3d2e75a6 100644 --- a/format.cc +++ b/format.cc @@ -451,6 +451,7 @@ const uint64_t fmt::internal::BasicData::POWERS_OF_10_64[] = { }; FMT_FUNC void fmt::internal::report_unknown_type(char code, const char *type) { + (void)type; if (std::isprint(static_cast(code))) { FMT_THROW(fmt::FormatError( fmt::format("unknown format code '{}' for {}", code, type))); @@ -725,6 +726,7 @@ void fmt::internal::PrintfFormatter::parse_flags( template Arg fmt::internal::PrintfFormatter::get_arg( const Char *s, unsigned arg_index) { + (void)s; const char *error = 0; Arg arg = arg_index == UINT_MAX ? next_arg(error) : FormatterBase::get_arg(arg_index - 1, error); From 80d1dd29b715bc1b088659f1c169a219c056f746 Mon Sep 17 00:00:00 2001 From: Carter Li Date: Sun, 15 Mar 2015 09:25:36 +0800 Subject: [PATCH 3/3] Feedback --- format.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/format.cc b/format.cc index 34522bbc..5365ffdd 100644 --- a/format.cc +++ b/format.cc @@ -67,7 +67,7 @@ using fmt::internal::Arg; # if FMT_EXCEPTIONS # define FMT_THROW(x) throw x # else -# ifdef DEBUG +# ifndef NDEBUG # define FMT_THROW(x) assert(false && #x) # elif defined _MSC_VER # define FMT_THROW(x) __assume(0) @@ -84,6 +84,8 @@ using fmt::internal::Arg; # define FMT_NORETURN __attribute__((__noreturn__)) # elif defined _MSC_VER # define FMT_NORETURN __declspec(noreturn) +# else +# define FMT_NORETURN # endif #endif