mirror of
https://github.com/fmtlib/fmt.git
synced 2024-11-19 20:18:49 +00:00
Merge pull request #134 from CarterLi/master
Improve behaviors when disabling exceptions
This commit is contained in:
commit
e65e05b960
28
format.cc
28
format.cc
@ -66,10 +66,26 @@ using fmt::internal::Arg;
|
|||||||
#ifndef FMT_THROW
|
#ifndef FMT_THROW
|
||||||
# if FMT_EXCEPTIONS
|
# if FMT_EXCEPTIONS
|
||||||
# define FMT_THROW(x) throw x
|
# define FMT_THROW(x) throw x
|
||||||
# define FMT_RETURN_AFTER_THROW(x)
|
|
||||||
# else
|
# else
|
||||||
# define FMT_THROW(x) assert(false)
|
# ifndef NDEBUG
|
||||||
# define FMT_RETURN_AFTER_THROW(x) return x
|
# 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)
|
||||||
|
# else
|
||||||
|
# define FMT_NORETURN
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -286,9 +302,9 @@ class WidthHandler : public fmt::internal::ArgVisitor<WidthHandler, unsigned> {
|
|||||||
public:
|
public:
|
||||||
explicit WidthHandler(fmt::FormatSpec &spec) : spec_(spec) {}
|
explicit WidthHandler(fmt::FormatSpec &spec) : spec_(spec) {}
|
||||||
|
|
||||||
|
FMT_NORETURN
|
||||||
unsigned visit_unhandled_arg() {
|
unsigned visit_unhandled_arg() {
|
||||||
FMT_THROW(fmt::FormatError("width is not integer"));
|
FMT_THROW(fmt::FormatError("width is not integer"));
|
||||||
FMT_RETURN_AFTER_THROW(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
@ -308,9 +324,9 @@ class WidthHandler : public fmt::internal::ArgVisitor<WidthHandler, unsigned> {
|
|||||||
class PrecisionHandler :
|
class PrecisionHandler :
|
||||||
public fmt::internal::ArgVisitor<PrecisionHandler, int> {
|
public fmt::internal::ArgVisitor<PrecisionHandler, int> {
|
||||||
public:
|
public:
|
||||||
|
FMT_NORETURN
|
||||||
unsigned visit_unhandled_arg() {
|
unsigned visit_unhandled_arg() {
|
||||||
FMT_THROW(fmt::FormatError("precision is not integer"));
|
FMT_THROW(fmt::FormatError("precision is not integer"));
|
||||||
FMT_RETURN_AFTER_THROW(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
@ -466,6 +482,7 @@ const uint64_t fmt::internal::BasicData<T>::POWERS_OF_10_64[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
FMT_FUNC void fmt::internal::report_unknown_type(char code, const char *type) {
|
FMT_FUNC void fmt::internal::report_unknown_type(char code, const char *type) {
|
||||||
|
(void)type;
|
||||||
if (std::isprint(static_cast<unsigned char>(code))) {
|
if (std::isprint(static_cast<unsigned char>(code))) {
|
||||||
FMT_THROW(fmt::FormatError(
|
FMT_THROW(fmt::FormatError(
|
||||||
fmt::format("unknown format code '{}' for {}", code, type)));
|
fmt::format("unknown format code '{}' for {}", code, type)));
|
||||||
@ -740,6 +757,7 @@ void fmt::internal::PrintfFormatter<Char>::parse_flags(
|
|||||||
template <typename Char>
|
template <typename Char>
|
||||||
Arg fmt::internal::PrintfFormatter<Char>::get_arg(
|
Arg fmt::internal::PrintfFormatter<Char>::get_arg(
|
||||||
const Char *s, unsigned arg_index) {
|
const Char *s, unsigned arg_index) {
|
||||||
|
(void)s;
|
||||||
const char *error = 0;
|
const char *error = 0;
|
||||||
Arg arg = arg_index == UINT_MAX ?
|
Arg arg = arg_index == UINT_MAX ?
|
||||||
next_arg(error) : FormatterBase::get_arg(arg_index - 1, error);
|
next_arg(error) : FormatterBase::get_arg(arg_index - 1, error);
|
||||||
|
Loading…
Reference in New Issue
Block a user