From 1e8493196efa4e05baa22461ba61b636ab2e662b Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sun, 1 Mar 2020 07:57:34 -0800 Subject: [PATCH] Make compile-time checks in format_to handle references --- include/fmt/core.h | 2 +- include/fmt/format.h | 7 +++---- test/format-test.cc | 2 ++ 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index f5eb7e3ae895..0e6422d9f1a9 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -1460,7 +1460,7 @@ make_args_checked(const S& format_str, all_true<(!std::is_base_of>::value || !std::is_reference::value)...>::value, "passing views as lvalues is disallowed"); - check_format_string>...>(format_str); + check_format_string(format_str); return {args...}; } diff --git a/include/fmt/format.h b/include/fmt/format.h index acd7d9dc0bad..5d36a68276b5 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -2641,10 +2641,9 @@ FMT_CONSTEXPR bool do_check_format_string(basic_string_view s, template ::value), int>> void check_format_string(S format_str) { - FMT_CONSTEXPR_DECL bool invalid_format = - internal::do_check_format_string( - to_string_view(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)); (void)invalid_format; } diff --git a/test/format-test.cc b/test/format-test.cc index 8bce69be20d9..b17306300bab 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -1859,6 +1859,8 @@ TEST(FormatTest, CustomFormatCompileTimeString) { EXPECT_EQ("42", fmt::format(FMT_STRING("{}"), Answer())); Answer answer; EXPECT_EQ("42", fmt::format(FMT_STRING("{}"), answer)); + char buf[10] = {}; + fmt::format_to(buf, FMT_STRING("{}"), answer); const Answer const_answer = Answer(); EXPECT_EQ("42", fmt::format(FMT_STRING("{}"), const_answer)); }