diff --git a/format.cc b/format.cc index a4c9cee6..5a764a84 100644 --- a/format.cc +++ b/format.cc @@ -66,8 +66,10 @@ using fmt::internal::Arg; #ifndef FMT_THROW # if FMT_EXCEPTIONS # define FMT_THROW(x) throw x +# define FMT_RETURNAFTERTHROW(x) # else # define FMT_THROW(x) assert(false) +# define FMT_RETURNAFTERTHROW(x) return x # endif #endif @@ -251,7 +253,7 @@ class WidthHandler : public fmt::internal::ArgVisitor { unsigned visit_unhandled_arg() { FMT_THROW(fmt::FormatError("width is not integer")); - return 0; + FMT_RETURNAFTERTHROW(0); } template @@ -273,7 +275,7 @@ class PrecisionHandler : public: unsigned visit_unhandled_arg() { FMT_THROW(fmt::FormatError("precision is not integer")); - return 0; + FMT_RETURNAFTERTHROW(0); } template @@ -625,7 +627,7 @@ void fmt::BasicWriter::write_str( if (*str_value) str_size = std::char_traits::length(str_value); } - if (spec.precision_ >= 0 && spec.precision_ < str_size) + if (spec.precision_ >= 0 && static_cast(spec.precision_) < str_size) str_size = spec.precision_; write_str(str_value, str_size, spec); } diff --git a/format.h b/format.h index 2baa259a..86485dcb 100644 --- a/format.h +++ b/format.h @@ -60,6 +60,16 @@ # define FMT_GCC_EXTENSION #endif +#define FMT_CLANGFALLTHROUGH + +#ifdef __clang__ + #pragma clang diagnostic ignored "-Wdocumentation-unknown-command" + #ifdef NDEBUG + #undef FMT_CLANGFALLTHROUGH + #define FMT_CLANGFALLTHROUGH [[clang::fallthrough]]; + #endif +#endif + #ifdef __GNUC_LIBSTD__ # define FMT_GNUC_LIBSTD_VERSION (__GNUC_LIBSTD__ * 100 + __GNUC_LIBSTD_MINOR__) #endif @@ -865,7 +875,8 @@ class ArgVisitor { default: assert(false); // Fall through. - case Arg::INT: + FMT_CLANGFALLTHROUGH + case Arg::INT: return FMT_DISPATCH(visit_int(arg.int_value)); case Arg::UINT: return FMT_DISPATCH(visit_uint(arg.uint_value)); @@ -2442,6 +2453,10 @@ FMT_VARIADIC(int, fprintf, std::FILE *, StringRef) # pragma GCC diagnostic pop #endif +#ifdef __clang__ +# pragma clang diagnostic pop +#endif + #ifdef FMT_HEADER_ONLY # include "format.cc" #endif