Skip to content

Commit

Permalink
Fix formatting of abstract classes via ostream
Browse files Browse the repository at this point in the history
vitaut committed Sep 2, 2021
1 parent 8029bf9 commit ee0659f
Showing 2 changed files with 17 additions and 3 deletions.
7 changes: 4 additions & 3 deletions include/fmt/format.h
Original file line number Diff line number Diff line change
@@ -579,9 +579,10 @@ inline auto code_point_index(basic_string_view<char8_type> s, size_t n)
return s.size();
}

template <typename T>
using is_fast_float = bool_constant<std::numeric_limits<T>::is_iec559 &&
sizeof(T) <= sizeof(double)>;
template <typename T, bool = std::is_floating_point<T>::value>
struct is_fast_float : bool_constant<std::numeric_limits<T>::is_iec559 &&
sizeof(T) <= sizeof(double)> {};
template <typename T> struct is_fast_float<T, false> : std::false_type {};

#ifndef FMT_USE_FULL_CACHE_DRAGONBOX
# define FMT_USE_FULL_CACHE_DRAGONBOX 0
13 changes: 13 additions & 0 deletions test/ostream-test.cc
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@ template <> struct formatter<test> : formatter<int> {

#include <sstream>

#include "fmt/compile.h"
#include "fmt/ostream.h"
#include "fmt/ranges.h"
#include "gmock/gmock.h"
@@ -280,3 +281,15 @@ TEST(ostream_test, range) {
auto strs = std::vector<test_string>{test_string("foo"), test_string("bar")};
EXPECT_EQ("[foo, bar]", fmt::format("{}", strs));
}

struct abstract {
virtual ~abstract() = default;
virtual void f() = 0;
friend std::ostream& operator<<(std::ostream& os, const abstract&) {
return os;
}
};

void format_abstract_compiles(const abstract& a) {
fmt::format(FMT_COMPILE("{}"), a);
}

0 comments on commit ee0659f

Please sign in to comment.