diff --git a/include/fmt/ostream.h b/include/fmt/ostream.h index 938d1176..18ae820c 100644 --- a/include/fmt/ostream.h +++ b/include/fmt/ostream.h @@ -49,6 +49,10 @@ template struct test_stream : std::basic_ostream { // Hide all operator<< from std::basic_ostream. void_t<> operator<<(null<>); void_t<> operator<<(const Char*); + + template ::value && + !std::is_enum::value)> + void_t<> operator<<(T); }; // Checks if T has a user-defined operator<< (e.g. not a member of diff --git a/test/ostream-test.cc b/test/ostream-test.cc index 6c2bc412..7be783d5 100644 --- a/test/ostream-test.cc +++ b/test/ostream-test.cc @@ -250,7 +250,8 @@ struct convertible { operator T() const { return value; } }; -TEST(OStreamTest, ConvertibleToCString) { - EXPECT_EQ("x", fmt::format("{}", convertible('x'))); +TEST(OStreamTest, DisableBuiltinOStreamOperators) { + EXPECT_EQ("42", fmt::format("{:d}", convertible(42))); + EXPECT_EQ(L"42", fmt::format(L"{:d}", convertible(42))); EXPECT_EQ("foo", fmt::format("{}", convertible("foo"))); }