https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106201
--- Comment #10 from Jonathan Wakely <redi at gcc dot gnu.org> --- I'm planning to use this workaround for gcc-11 and gcc-12: --- a/libstdc++-v3/include/bits/fs_path.h +++ b/libstdc++-v3/include/bits/fs_path.h @@ -737,7 +737,14 @@ namespace __detail /// @{ /// @relates std::filesystem::path +#if __cpp_concepts >= 201907L + // Workaround for PR libstdc++/106201 + inline void + swap(same_as<path> auto& __lhs, same_as<path> auto& __rhs) noexcept + { __lhs.swap(__rhs); } +#else inline void swap(path& __lhs, path& __rhs) noexcept { __lhs.swap(__rhs); } +#endif size_t hash_value(const path& __p) noexcept; This will prevent that swap overload from being a candidate for swapping counted_iterator<filesystem::directory_iterator>, so we won't check for conversion to path& and hit the constraint recursion.