diff --git a/src/core-fmt/include/units/bits/fmt.h b/src/core-fmt/include/units/bits/fmt.h index 7c449306..f93c316d 100644 --- a/src/core-fmt/include/units/bits/fmt.h +++ b/src/core-fmt/include/units/bits/fmt.h @@ -55,7 +55,7 @@ public: constexpr fill_t& operator=(std::basic_string_view str) { auto size = str.size(); - if (size > max_size) throw STD_FMT::format_error("invalid fill"); + if (size > max_size) FMT_THROW(STD_FMT::format_error("invalid fill")); for (size_t i = 0; i < size; ++i) data_[i] = str[i]; size_ = static_cast(size); return *this; @@ -98,11 +98,11 @@ struct width_checker { { if constexpr (is_integer) { if constexpr (std::numeric_limits::is_signed) { - if (value < 0) throw STD_FMT::format_error("negative width"); + if (value < 0) FMT_THROW(STD_FMT::format_error("negative width")); } return static_cast(value); } else { - throw STD_FMT::format_error("width is not integer"); + FMT_THROW(STD_FMT::format_error("width is not integer")); } } }; @@ -113,11 +113,11 @@ struct precision_checker { { if constexpr (is_integer) { if constexpr (std::numeric_limits::is_signed) { - if (value < 0) throw STD_FMT::format_error("negative precision"); + if (value < 0) FMT_THROW(STD_FMT::format_error("negative precision")); } return static_cast(value); } else { - throw STD_FMT::format_error("precision is not integer"); + FMT_THROW(STD_FMT::format_error("precision is not integer")); } } }; @@ -147,7 +147,7 @@ struct dynamic_format_specs : basic_format_specs { [[nodiscard]] constexpr int verify_dynamic_arg_index_in_range(size_t idx) { if (idx > static_cast(std::numeric_limits::max())) { - throw STD_FMT::format_error("Dynamic width or precision index too large."); + FMT_THROW(STD_FMT::format_error("Dynamic width or precision index too large.")); } return static_cast(idx); } @@ -171,7 +171,7 @@ template const unsigned long long value = STD_FMT::visit_format_arg(Handler{}, ctx.arg(FMT_TO_ARG_ID(static_cast(index)))); if (value > static_cast(std::numeric_limits::max())) { - throw STD_FMT::format_error("number is too big"); + FMT_THROW(STD_FMT::format_error("number is too big")); } return static_cast(value); } @@ -195,7 +195,7 @@ template S> ++begin; } while (begin != end && '0' <= *begin && *begin <= '9'); - if (value > max_int) throw STD_FMT::format_error("Number is too big"); + if (value > max_int) FMT_THROW(STD_FMT::format_error("Number is too big")); return begin; } @@ -222,12 +222,12 @@ template S, typename IDHandler> else ++begin; if (begin == end || (*begin != '}' && *begin != ':')) - throw STD_FMT::format_error("invalid format string"); + FMT_THROW(STD_FMT::format_error("invalid format string")); else handler(index); return begin; } - throw STD_FMT::format_error("invalid format string"); + FMT_THROW(STD_FMT::format_error("invalid format string")); } template S, typename IDHandler> @@ -278,11 +278,11 @@ template S, typename Handler> if (width != -1) handler.on_width(width); else - throw STD_FMT::format_error("number is too big"); + FMT_THROW(STD_FMT::format_error("number is too big")); } else if (*begin == '{') { ++begin; if (begin != end) begin = parse_arg_id(begin, end, width_adapter{handler}); - if (begin == end || *begin != '}') throw STD_FMT::format_error("invalid format string"); + if (begin == end || *begin != '}') FMT_THROW(STD_FMT::format_error("invalid format string")); ++begin; } return begin; @@ -305,13 +305,13 @@ template S, typename Handler> if (precision != -1) handler.on_precision(precision); else - throw STD_FMT::format_error("number is too big"); + FMT_THROW(STD_FMT::format_error("number is too big")); } else if (c == '{') { ++begin; if (begin != end) begin = parse_arg_id(begin, end, precision_adapter{handler}); - if (begin == end || *begin++ != '}') throw STD_FMT::format_error("invalid format string"); + if (begin == end || *begin++ != '}') FMT_THROW(STD_FMT::format_error("invalid format string")); } else { - throw STD_FMT::format_error("missing precision specifier"); + FMT_THROW(STD_FMT::format_error("missing precision specifier")); } return begin; } @@ -355,7 +355,7 @@ template S, typename Handler> if (align != fmt_align::none) { if (p != begin) { auto c = *begin; - if (c == '{') throw STD_FMT::format_error("invalid fill character '{'"); + if (c == '{') FMT_THROW(STD_FMT::format_error("invalid fill character '{'")); handler.on_fill(std::basic_string_view>(&*begin, static_cast(p - begin))); begin = p + 1; } else diff --git a/src/core-fmt/include/units/bits/fmt_hacks.h b/src/core-fmt/include/units/bits/fmt_hacks.h index a4db23f2..3d8c0d80 100644 --- a/src/core-fmt/include/units/bits/fmt_hacks.h +++ b/src/core-fmt/include/units/bits/fmt_hacks.h @@ -38,7 +38,7 @@ UNITS_DIAGNOSTIC_PUSH UNITS_DIAGNOSTIC_IGNORE_UNREACHABLE UNITS_DIAGNOSTIC_IGNORE_SHADOW -#include +#include UNITS_DIAGNOSTIC_POP #define STD_FMT fmt @@ -58,5 +58,6 @@ UNITS_DIAGNOSTIC_POP #define FMT_LOCALE(loc) loc #define FMT_TO_ARG_ID(arg) arg #define FMT_FROM_ARG_ID(arg) arg +#define FMT_THROW(arg) throw arg #endif