diff --git a/include/fmt/format.h b/include/fmt/format.h index ce81274c..d11a714b 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -2723,20 +2723,14 @@ FMT_CONSTEXPR basic_string_view compile_string_to_view( # define fmt(s) FMT_STRING_IMPL(s, [[deprecated]]) #endif -template -FMT_CONSTEXPR bool do_check_format_string(basic_string_view s, - ErrorHandler eh = ErrorHandler()) { - format_string_checker checker(s, eh); - parse_format_string(s, checker); - return true; -} - template ::value), int>> void check_format_string(S format_str) { - FMT_CONSTEXPR_DECL bool invalid_format = internal::do_check_format_string< - typename S::char_type, internal::error_handler, - remove_const_t>...>(to_string_view(format_str)); + FMT_CONSTEXPR_DECL auto s = to_string_view(format_str); + using checker = format_string_checker...>; + FMT_CONSTEXPR_DECL bool invalid_format = + (parse_format_string(s, checker(s, {})), true); (void)invalid_format; } diff --git a/test/format-test.cc b/test/format-test.cc index 63dc4504..fa3574bc 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -647,8 +647,7 @@ TEST(FormatterTest, ArgErrors) { safe_sprintf(format_str, "{%u", INT_MAX); EXPECT_THROW_MSG(format(format_str), format_error, "invalid format string"); safe_sprintf(format_str, "{%u}", INT_MAX); - EXPECT_THROW_MSG(format(format_str), format_error, - "argument not found"); + EXPECT_THROW_MSG(format(format_str), format_error, "argument not found"); safe_sprintf(format_str, "{%u", INT_MAX + 1u); EXPECT_THROW_MSG(format(format_str), format_error, "number is too big"); @@ -1011,8 +1010,7 @@ TEST(FormatterTest, RuntimeWidth) { EXPECT_THROW_MSG(format("{0:{}", 0), format_error, "cannot switch from manual to automatic argument indexing"); EXPECT_THROW_MSG(format("{0:{?}}", 0), format_error, "invalid format string"); - EXPECT_THROW_MSG(format("{0:{1}}", 0), format_error, - "argument not found"); + EXPECT_THROW_MSG(format("{0:{1}}", 0), format_error, "argument not found"); EXPECT_THROW_MSG(format("{0:{0:}}", 0), format_error, "invalid format string"); @@ -1160,8 +1158,7 @@ TEST(FormatterTest, RuntimePrecision) { "invalid format string"); EXPECT_THROW_MSG(format("{0:.{1}", 0, 0), format_error, "precision not allowed for this argument type"); - EXPECT_THROW_MSG(format("{0:.{1}}", 0), format_error, - "argument not found"); + EXPECT_THROW_MSG(format("{0:.{1}}", 0), format_error, "argument not found"); EXPECT_THROW_MSG(format("{0:.{0:}}", 0), format_error, "invalid format string"); @@ -2456,8 +2453,10 @@ FMT_CONSTEXPR bool equal(const char* s1, const char* s2) { template FMT_CONSTEXPR bool test_error(const char* fmt, const char* expected_error) { const char* actual_error = nullptr; - fmt::internal::do_check_format_string( - string_view(fmt, len(fmt)), test_error_handler(actual_error)); + string_view s(fmt, len(fmt)); + fmt::internal::format_string_checker + checker(s, test_error_handler(actual_error)); + fmt::internal::parse_format_string(s, checker); return equal(actual_error, expected_error); }