From 699fe8e7112734b09985f84388dc91054a67de10 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Sun, 14 Jul 2019 16:16:13 -1000 Subject: [PATCH] Remove const qualification in compile-time checks --- include/fmt/core.h | 4 +++- test/format-test.cc | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index 08312f7c..632b7dfe 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -198,6 +198,8 @@ using conditional_t = typename std::conditional::type; template using bool_constant = std::integral_constant; template using remove_reference_t = typename std::remove_reference::type; +template +using remove_const_t = typename std::remove_const::type; struct monostate {}; @@ -1273,7 +1275,7 @@ make_args_checked(const S& format_str, static_assert(all_true<(!std::is_base_of>() || !std::is_reference())...>::value, "passing views as lvalues is disallowed"); - check_format_string...>(format_str); + check_format_string>...>(format_str); return {args...}; } diff --git a/test/format-test.cc b/test/format-test.cc index bca0b6f1..e4631b08 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -1854,6 +1854,14 @@ TEST(FormatTest, CompileTimeString) { EXPECT_EQ("foo", fmt::format(FMT_STRING("{}"), string_like())); } +TEST(FormatTest, CustomFormatCompileTimeString) { + EXPECT_EQ("42", fmt::format(FMT_STRING("{}"), Answer())); + Answer answer; + EXPECT_EQ("42", fmt::format(FMT_STRING("{}"), answer)); + const Answer const_answer; + EXPECT_EQ("42", fmt::format(FMT_STRING("{}"), const_answer)); +} + #if FMT_USE_USER_DEFINED_LITERALS // Passing user-defined literals directly to EXPECT_EQ causes problems // with macro argument stringification (#) on some versions of GCC.