From 20931baf1db555105c77aba5ae80aac51197f91c Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Fri, 3 Sep 2021 08:35:13 -0700 Subject: [PATCH] Disable fallback_formatter for arrays --- include/fmt/ostream.h | 8 ++++++-- test/header-only-test.cc | 4 ++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/include/fmt/ostream.h b/include/fmt/ostream.h index d66248a6..cee8273b 100644 --- a/include/fmt/ostream.h +++ b/include/fmt/ostream.h @@ -70,8 +70,7 @@ void_t<> operator<<(std::basic_ostream&, signed char); template void_t<> operator<<(std::basic_ostream&, unsigned char); -// Checks if T has a user-defined operator<< (e.g. not a member of -// std::ostream). +// Checks if T has a user-defined operator<< e.g. not a member of std::ostream. template class is_streamable { private: template @@ -90,6 +89,11 @@ template class is_streamable { static const bool value = result::value; }; +// Formatting of arrays is intentionally disabled to prevent conflicts with +// standard (non-ostream) formatters. +template +struct is_streamable : std::false_type {}; + // Write the content of buf to os. template void write_buffer(std::basic_ostream& os, buffer& buf) { diff --git a/test/header-only-test.cc b/test/header-only-test.cc index f0c3a7fa..570f09a5 100644 --- a/test/header-only-test.cc +++ b/test/header-only-test.cc @@ -1,7 +1,11 @@ // Header-only configuration test #include "fmt/core.h" +#include "fmt/ostream.h" +#include "gtest/gtest.h" #ifndef FMT_HEADER_ONLY # error "Not in the header-only mode." #endif + +TEST(header_only_test, format) { EXPECT_EQ(fmt::format("foo"), "foo"); }