mirror of
https://github.com/fmtlib/fmt.git
synced 2024-11-05 11:27:40 +00:00
Fix recursion check in range formatting
This commit is contained in:
parent
b94e1016fa
commit
e0748e61dd
@ -505,13 +505,14 @@ struct range_formatter<
|
|||||||
enum class range_format { disabled, map, set, sequence, string, debug_string };
|
enum class range_format { disabled, map, set, sequence, string, debug_string };
|
||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
template <typename T> struct range_format_kind_ {
|
template <typename T>
|
||||||
static constexpr auto value = std::is_same<range_reference_type<T>, T>::value
|
struct range_format_kind_
|
||||||
? range_format::disabled
|
: std::integral_constant<range_format,
|
||||||
: is_map<T>::value ? range_format::map
|
std::is_same<uncvref_type<T>, T>::value
|
||||||
: is_set<T>::value ? range_format::set
|
? range_format::disabled
|
||||||
: range_format::sequence;
|
: is_map<T>::value ? range_format::map
|
||||||
};
|
: is_set<T>::value ? range_format::set
|
||||||
|
: range_format::sequence> {};
|
||||||
|
|
||||||
template <range_format K, typename R, typename Char, typename Enable = void>
|
template <range_format K, typename R, typename Char, typename Enable = void>
|
||||||
struct range_default_formatter;
|
struct range_default_formatter;
|
||||||
|
@ -179,15 +179,20 @@ TEST(ranges_test, format_to) {
|
|||||||
EXPECT_STREQ(buf, "[1, 2, 3]");
|
EXPECT_STREQ(buf, "[1, 2, 3]");
|
||||||
}
|
}
|
||||||
|
|
||||||
struct path_like {
|
template <typename Char> struct path_like {
|
||||||
const path_like* begin() const;
|
const path_like* begin() const;
|
||||||
const path_like* end() const;
|
const path_like* end() const;
|
||||||
|
|
||||||
operator std::string() const;
|
operator std::basic_string<Char>() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST(ranges_test, path_like) {
|
TEST(ranges_test, disabled_range_formatting_of_path) {
|
||||||
EXPECT_FALSE((fmt::is_range<path_like, char>::value));
|
// Range formatting of path is disabled because of infinite recursion
|
||||||
|
// (path element is itself a path).
|
||||||
|
EXPECT_EQ((fmt::range_format_kind<path_like<char>, char>::value),
|
||||||
|
fmt::range_format::disabled);
|
||||||
|
EXPECT_EQ((fmt::range_format_kind<path_like<wchar_t>, char>::value),
|
||||||
|
fmt::range_format::disabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
// A range that provides non-const only begin()/end() to test fmt::join
|
// A range that provides non-const only begin()/end() to test fmt::join
|
||||||
|
Loading…
Reference in New Issue
Block a user