Commit f2990109 authored by Victor Zverovich's avatar Victor Zverovich

Don't use const char* overload of operator<< (#1309)

parent 758446c8
...@@ -46,9 +46,9 @@ template <class Char> class formatbuf : public std::basic_streambuf<Char> { ...@@ -46,9 +46,9 @@ template <class Char> class formatbuf : public std::basic_streambuf<Char> {
template <typename Char> struct test_stream : std::basic_ostream<Char> { template <typename Char> struct test_stream : std::basic_ostream<Char> {
private: private:
struct null;
// Hide all operator<< from std::basic_ostream<Char>. // Hide all operator<< from std::basic_ostream<Char>.
void operator<<(null); void_t<> operator<<(null<>);
void_t<> operator<<(const Char*);
}; };
// Checks if T has a user-defined operator<< (e.g. not a member of // Checks if T has a user-defined operator<< (e.g. not a member of
...@@ -56,9 +56,9 @@ template <typename Char> struct test_stream : std::basic_ostream<Char> { ...@@ -56,9 +56,9 @@ template <typename Char> struct test_stream : std::basic_ostream<Char> {
template <typename T, typename Char> class is_streamable { template <typename T, typename Char> class is_streamable {
private: private:
template <typename U> template <typename U>
static decltype((void)(std::declval<test_stream<Char>&>() static bool_constant<!std::is_same<decltype(std::declval<test_stream<Char>&>()
<< std::declval<U>()), << std::declval<U>()),
std::true_type()) void_t<>>::value>
test(int); test(int);
template <typename> static std::false_type test(...); template <typename> static std::false_type test(...);
......
...@@ -242,3 +242,15 @@ TEST(FormatTest, UDL) { ...@@ -242,3 +242,15 @@ TEST(FormatTest, UDL) {
EXPECT_EQ("{}"_format("test"), "test"); EXPECT_EQ("{}"_format("test"), "test");
} }
#endif #endif
template <typename T>
struct convertible {
T value;
explicit convertible(const T& val) : value(val) {}
operator T() const { return value; }
};
TEST(OStreamTest, ConvertibleToCString) {
EXPECT_EQ("x", fmt::format("{}", convertible<char>('x')));
EXPECT_EQ("foo", fmt::format("{}", convertible<const char*>("foo")));
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment