From b2d4ca154633d44765b87aac580ea59d8202dcd5 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Wed, 21 Aug 2019 11:22:59 -0700 Subject: [PATCH] Workaround an issue with std::filesystem::path being an infinitely deep range (#1268) --- include/fmt/ranges.h | 9 ++++++--- test/ranges-test.cc | 11 +++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/include/fmt/ranges.h b/include/fmt/ranges.h index e6540108..cf0d41aa 100644 --- a/include/fmt/ranges.h +++ b/include/fmt/ranges.h @@ -242,13 +242,16 @@ struct formatter::value>> { } }; -template struct is_range { +template struct is_range { static FMT_CONSTEXPR_DECL const bool value = - internal::is_range_::value && !internal::is_like_std_string::value; + internal::is_range_::value && + !internal::is_like_std_string::value && + !std::is_convertible>::value; }; template -struct formatter::value>> { +struct formatter::value>> { formatting_range formatting; template diff --git a/test/ranges-test.cc b/test/ranges-test.cc index acddd0d5..7d4b6d24 100644 --- a/test/ranges-test.cc +++ b/test/ranges-test.cc @@ -87,5 +87,16 @@ TEST(RangesTest, FormatTo) { EXPECT_STREQ(buf, "{1, 2, 3}"); } +struct path_like { + const path_like* begin() const; + const path_like* end() const; + + operator std::string() const; +}; + +TEST(RangesTest, PathLike) { + EXPECT_FALSE((fmt::is_range::value)); +} + #endif // (__cplusplus > 201402L) || (defined(_MSVC_LANG) && _MSVC_LANG > // 201402L && _MSC_VER >= 1910)