mirror of
https://github.com/fmtlib/fmt.git
synced 2025-07-31 11:17:35 +02:00
Make copyfmt not throw (#1666)
This commit is contained in:
@ -101,8 +101,8 @@ void format_value(buffer<Char>& buf, const T& value,
|
|||||||
#if !defined(FMT_STATIC_THOUSANDS_SEPARATOR)
|
#if !defined(FMT_STATIC_THOUSANDS_SEPARATOR)
|
||||||
if (loc) output.imbue(loc.get<std::locale>());
|
if (loc) output.imbue(loc.get<std::locale>());
|
||||||
#endif
|
#endif
|
||||||
output.exceptions(std::ios_base::failbit | std::ios_base::badbit);
|
|
||||||
output << value;
|
output << value;
|
||||||
|
output.exceptions(std::ios_base::failbit | std::ios_base::badbit);
|
||||||
buf.resize(buf.size());
|
buf.resize(buf.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,9 +21,9 @@ template <> struct formatter<test> : formatter<int> {
|
|||||||
};
|
};
|
||||||
} // namespace fmt
|
} // namespace fmt
|
||||||
|
|
||||||
#include "fmt/ostream.h"
|
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
|
#include "fmt/ostream.h"
|
||||||
#include "gmock.h"
|
#include "gmock.h"
|
||||||
#include "gtest-extra.h"
|
#include "gtest-extra.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
@ -269,7 +269,7 @@ std::ostream& operator<<(std::ostream& os,
|
|||||||
return os << "bar";
|
return os << "bar";
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(FormatterTest, FormatExplicitlyConvertibleToStringLike) {
|
TEST(OStreamTest, FormatExplicitlyConvertibleToStringLike) {
|
||||||
EXPECT_EQ("bar", fmt::format("{}", explicitly_convertible_to_string_like()));
|
EXPECT_EQ("bar", fmt::format("{}", explicitly_convertible_to_string_like()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -285,8 +285,20 @@ std::ostream& operator<<(std::ostream& os,
|
|||||||
return os << "bar";
|
return os << "bar";
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(FormatterTest, FormatExplicitlyConvertibleToStdStringView) {
|
TEST(OStreamTest, FormatExplicitlyConvertibleToStdStringView) {
|
||||||
EXPECT_EQ("bar", fmt::format("{}", explicitly_convertible_to_string_like()));
|
EXPECT_EQ("bar", fmt::format("{}", explicitly_convertible_to_string_like()));
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // FMT_USE_STRING_VIEW
|
#endif // FMT_USE_STRING_VIEW
|
||||||
|
|
||||||
|
struct copyfmt_test {};
|
||||||
|
|
||||||
|
std::ostream& operator<<(std::ostream& os, copyfmt_test) {
|
||||||
|
std::ios ios(nullptr);
|
||||||
|
ios.copyfmt(os);
|
||||||
|
return os << "foo";
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(OStreamTest, CopyFmt) {
|
||||||
|
EXPECT_EQ("foo", fmt::format("{}", copyfmt_test()));
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user