From c26349f4d25d4542d99092afb9a4f9f141afb900 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Tue, 14 Jul 2020 11:13:21 -0700 Subject: [PATCH] Improve error reporting --- include/fmt/core.h | 9 ++++----- test/compile-test.cc | 12 ++++++------ 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index 891555d4..3805d44e 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -1214,6 +1214,8 @@ struct is_contiguous> : std::true_type {}; template struct is_contiguous> : std::true_type {}; +template struct formattable : std::false_type {}; + namespace detail { template @@ -1258,14 +1260,11 @@ FMT_CONSTEXPR basic_format_arg make_arg(const T& value) { return arg; } -template struct formattable : std::false_type {}; - template int check(unformattable) { static_assert( formattable(), - "Cannot format argument. To make type T formattable provide a " - "formatter specialization: " - "https://fmt.dev/latest/api.html#formatting-user-defined-types"); + "Cannot format an argument. To make type T formattable provide a " + "formatter specialization: https://fmt.dev/dev/api.html#udt"); return 0; } template inline const U& check(const U& val) { diff --git a/test/compile-test.cc b/test/compile-test.cc index c4d7ce74..6dca548d 100644 --- a/test/compile-test.cc +++ b/test/compile-test.cc @@ -114,20 +114,20 @@ TEST(CompileTest, MultipleTypes) { EXPECT_EQ(fmt::format(f, 42, 42), "42 42"); } -struct formattable {}; +struct test_formattable {}; FMT_BEGIN_NAMESPACE -template <> struct formatter : formatter { +template <> struct formatter : formatter { template - auto format(formattable, FormatContext& ctx) -> decltype(ctx.out()) { + auto format(test_formattable, FormatContext& ctx) -> decltype(ctx.out()) { return formatter::format("foo", ctx); } }; FMT_END_NAMESPACE TEST(CompileTest, FormatUserDefinedType) { - auto f = fmt::detail::compile("{}"); - EXPECT_EQ(fmt::format(f, formattable()), "foo"); + auto f = fmt::detail::compile("{}"); + EXPECT_EQ(fmt::format(f, test_formattable()), "foo"); } TEST(CompileTest, EmptyFormatString) { @@ -146,7 +146,7 @@ TEST(CompileTest, FormatDefault) { EXPECT_EQ("4.2", fmt::format(FMT_COMPILE("{}"), 4.2)); EXPECT_EQ("foo", fmt::format(FMT_COMPILE("{}"), "foo")); EXPECT_EQ("foo", fmt::format(FMT_COMPILE("{}"), std::string("foo"))); - EXPECT_EQ("foo", fmt::format(FMT_COMPILE("{}"), formattable())); + EXPECT_EQ("foo", fmt::format(FMT_COMPILE("{}"), test_formattable())); } TEST(CompileTest, FormatSpecs) {