Skip to content

Commit 8f511fc

Browse files
committed
Make copyfmt not throw (#1666)
1 parent 59fe455 commit 8f511fc

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

include/fmt/ostream.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ void format_value(buffer<Char>& buf, const T& value,
101101
#if !defined(FMT_STATIC_THOUSANDS_SEPARATOR)
102102
if (loc) output.imbue(loc.get<std::locale>());
103103
#endif
104-
output.exceptions(std::ios_base::failbit | std::ios_base::badbit);
105104
output << value;
105+
output.exceptions(std::ios_base::failbit | std::ios_base::badbit);
106106
buf.resize(buf.size());
107107
}
108108

test/ostream-test.cc

+16-4
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ template <> struct formatter<test> : formatter<int> {
2121
};
2222
} // namespace fmt
2323

24-
#include "fmt/ostream.h"
25-
2624
#include <sstream>
25+
26+
#include "fmt/ostream.h"
2727
#include "gmock.h"
2828
#include "gtest-extra.h"
2929
#include "util.h"
@@ -269,7 +269,7 @@ std::ostream& operator<<(std::ostream& os,
269269
return os << "bar";
270270
}
271271

272-
TEST(FormatterTest, FormatExplicitlyConvertibleToStringLike) {
272+
TEST(OStreamTest, FormatExplicitlyConvertibleToStringLike) {
273273
EXPECT_EQ("bar", fmt::format("{}", explicitly_convertible_to_string_like()));
274274
}
275275

@@ -285,8 +285,20 @@ std::ostream& operator<<(std::ostream& os,
285285
return os << "bar";
286286
}
287287

288-
TEST(FormatterTest, FormatExplicitlyConvertibleToStdStringView) {
288+
TEST(OStreamTest, FormatExplicitlyConvertibleToStdStringView) {
289289
EXPECT_EQ("bar", fmt::format("{}", explicitly_convertible_to_string_like()));
290290
}
291291

292292
#endif // FMT_USE_STRING_VIEW
293+
294+
struct copyfmt_test {};
295+
296+
std::ostream& operator<<(std::ostream& os, copyfmt_test) {
297+
std::ios ios(nullptr);
298+
ios.copyfmt(os);
299+
return os << "foo";
300+
}
301+
302+
TEST(OStreamTest, CopyFmt) {
303+
EXPECT_EQ("foo", fmt::format("{}", copyfmt_test()));
304+
}

0 commit comments

Comments
 (0)