Skip to content

Commit

Permalink
Disable fallback_formatter for arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed Sep 3, 2021
1 parent d58d19b commit 20931ba
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 6 additions & 2 deletions include/fmt/ostream.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ void_t<> operator<<(std::basic_ostream<char, Traits>&, signed char);
template <typename Traits>
void_t<> operator<<(std::basic_ostream<char, Traits>&, 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 <typename T, typename Char> class is_streamable {
private:
template <typename U>
Expand All @@ -90,6 +89,11 @@ template <typename T, typename Char> class is_streamable {
static const bool value = result::value;
};

// Formatting of arrays is intentionally disabled to prevent conflicts with
// standard (non-ostream) formatters.
template <typename T, size_t N, typename Char>
struct is_streamable<T[N], Char> : std::false_type {};

// Write the content of buf to os.
template <typename Char>
void write_buffer(std::basic_ostream<Char>& os, buffer<Char>& buf) {
Expand Down
4 changes: 4 additions & 0 deletions test/header-only-test.cc
Original file line number Diff line number Diff line change
@@ -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"); }

0 comments on commit 20931ba

Please sign in to comment.