diff --git a/include/fmt/format.h b/include/fmt/format.h index 97358d04..57d410ce 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -2096,10 +2096,14 @@ FMT_CONSTEXPR void parse_format_string(basic_string_view format_str, template FMT_CONSTEXPR const typename ParseContext::char_type* parse_format_specs( ParseContext& ctx) { - // GCC 7.2 requires initializer. - typedef typename ParseContext::char_type char_type; - conditional_t>::value, - formatter, + using char_type = typename ParseContext::char_type; + using context = buffer_context; + using mapped_type = + conditional_t::value != + internal::custom_type, + decltype(arg_mapper().map(std::declval())), T>; + conditional_t::value, + formatter, internal::fallback_formatter> f; return f.parse(ctx); diff --git a/test/format-test.cc b/test/format-test.cc index 6c05854c..5d6df9a8 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -1836,6 +1836,15 @@ TEST(FormatTest, UnpackedArgs) { 6, 7, 8, 9, 'a', 'b', 'c', 'd', 'e', 'f', 'g')); } +struct string_like {}; +fmt::string_view to_string_view(string_like) { return "foo"; } + +TEST(FormatTest, CompileTimeString) { + EXPECT_EQ("42", fmt::format(FMT_STRING("{}"), 42)); + EXPECT_EQ(L"42", fmt::format(FMT_STRING(L"{}"), 42)); + EXPECT_EQ("foo", fmt::format(FMT_STRING("{}"), string_like())); +} + #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. @@ -1867,8 +1876,6 @@ TEST(LiteralsTest, NamedArg) { TEST(FormatTest, UdlTemplate) { EXPECT_EQ("foo", "foo"_format()); EXPECT_EQ(" 42", "{0:10}"_format(42)); - EXPECT_EQ("42", fmt::format(FMT_STRING("{}"), 42)); - EXPECT_EQ(L"42", fmt::format(FMT_STRING(L"{}"), 42)); } #endif // FMT_USE_USER_DEFINED_LITERALS