Skip to content

Commit

Permalink
Don't confuse Glib::ustring with std::string
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed Jul 6, 2024
1 parent b50e685 commit 7a8b54a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion include/fmt/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,8 @@ struct is_std_string_like : std::false_type {};
template <typename T>
struct is_std_string_like<T, void_t<decltype(std::declval<T>().find_first_of(
typename T::value_type(), 0))>>
: std::true_type {};
: std::is_convertible<decltype(std::declval<T>().data()),
const typename T::value_type*> {};

// Returns true iff the literal encoding is UTF-8.
constexpr auto is_utf8_enabled() -> bool {
Expand Down
22 changes: 22 additions & 0 deletions test/format-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2420,3 +2420,25 @@ TEST(format_test, formatter_overrides_implicit_conversion) {
EXPECT_EQ(fmt::format("{}", convertible_to_int()), "x");
EXPECT_EQ(fmt::format("{}", convertible_to_cstring()), "y");
}

struct ustring {
using value_type = unsigned;

auto find_first_of(value_type, size_t) const -> size_t;

auto data() const -> const char*;
auto size() const -> size_t;
};

FMT_BEGIN_NAMESPACE
template <> struct formatter<ustring> : formatter<std::string> {
auto format(const ustring&, format_context& ctx) const
-> decltype(ctx.out()) {
return formatter<std::string>::format("ustring", ctx);
}
};
FMT_END_NAMESPACE

TEST(format_test, ustring) {
EXPECT_EQ(fmt::format("{}", ustring()), "ustring");
}

0 comments on commit 7a8b54a

Please sign in to comment.