diff --git a/include/fmt/core.h b/include/fmt/core.h index c62ffdf6..973094ec 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -493,15 +493,14 @@ using string_view = basic_string_view; template struct is_char : std::false_type {}; template <> struct is_char : std::true_type {}; -// A base class for compile-time strings. It is defined in the fmt namespace to -// make formatting functions visible via ADL, e.g. format(FMT_STRING("{}"), 42). +FMT_BEGIN_DETAIL_NAMESPACE + +// A base class for compile-time strings. struct compile_string {}; template struct is_compile_string : std::is_base_of {}; -FMT_BEGIN_DETAIL_NAMESPACE - // Returns a string view of `s`. template ::value)> FMT_INLINE auto to_string_view(const Char* s) -> basic_string_view { @@ -519,8 +518,7 @@ constexpr auto to_string_view(basic_string_view s) } template >::value)> -inline auto to_string_view(std_string_view s) - -> basic_string_view { +inline auto to_string_view(std_string_view s) -> basic_string_view { return s; } template ::value)> @@ -533,6 +531,7 @@ void to_string_view(...); // Specifies whether S is a string type convertible to fmt::basic_string_view. // It should be a constexpr function but MSVC 2017 fails to compile it in // enable_if and MSVC 2015 fails to compile it as an alias template. +// ADL invocation of to_string_view is DEPRECATED! template struct is_string : std::is_class()))> { }; @@ -2918,7 +2917,7 @@ FMT_INLINE void check_format_string(const S&) { template ::value)> void check_format_string(S format_str) { - FMT_CONSTEXPR auto s = to_string_view(format_str); + FMT_CONSTEXPR auto s = basic_string_view(format_str); using checker = format_string_checker...>; FMT_CONSTEXPR bool invalid_format = diff --git a/include/fmt/format.h b/include/fmt/format.h index 27285ad0..36b6137f 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -1762,7 +1762,7 @@ inline auto find_escape(const char* begin, const char* end) std::string s = fmt::format(FMT_STRING("{:d}"), "foo"); \endrst */ -#define FMT_STRING(s) FMT_STRING_IMPL(s, fmt::compile_string, ) +#define FMT_STRING(s) FMT_STRING_IMPL(s, fmt::detail::compile_string, ) template auto write_codepoint(OutputIt out, char prefix, uint32_t cp) -> OutputIt { diff --git a/test/ostream-test.cc b/test/ostream-test.cc index 3834c707..b6d0085d 100644 --- a/test/ostream-test.cc +++ b/test/ostream-test.cc @@ -165,8 +165,9 @@ TEST(ostream_test, join_fallback_formatter) { #if FMT_USE_CONSTEXPR TEST(ostream_test, constexpr_string) { - EXPECT_EQ("42", format(FMT_STRING("{}"), std::string("42"))); - EXPECT_EQ("a string", format(FMT_STRING("{0}"), test_string("a string"))); + EXPECT_EQ("42", fmt::format(FMT_STRING("{}"), std::string("42"))); + EXPECT_EQ("a string", + fmt::format(FMT_STRING("{0}"), test_string("a string"))); } #endif