From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 74D9D3858C1F; Tue, 22 Nov 2022 21:49:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 74D9D3858C1F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669153744; bh=P6rsvhLjqP/oiw/BRYj+mXz5Q1Ddu72cM6NYHqU/OnU=; h=From:To:Subject:Date:From; b=p2r7Kkpbsbtf2LJ1kkALSpvVq7CezicUtvPyt6mkJqjojU7y572d/dhE1xi1QOcrc ecCv0TK7cvX5N/jDBpZ/NV33xOkNc2iIBzBxOaNFv6w3Vh9CrGKNCVLiHdZLmRC4VK MIXW2NiefH+sKVdKhBw4UhFyGcCLOrbSaG8pE8OI= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r12-8927] libstdc++: Add workaround for fs::path constraint recursion [PR106201] X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/releases/gcc-12 X-Git-Oldrev: 691012693aaa831e4cd1ab5180195792e32baceb X-Git-Newrev: 477b3f9d58589b3af7a5a7d038d78352ad66406e Message-Id: <20221122214904.74D9D3858C1F@sourceware.org> Date: Tue, 22 Nov 2022 21:49:04 +0000 (GMT) List-Id: https://gcc.gnu.org/g:477b3f9d58589b3af7a5a7d038d78352ad66406e commit r12-8927-g477b3f9d58589b3af7a5a7d038d78352ad66406e Author: Jonathan Wakely Date: Tue Nov 22 18:15:56 2022 +0000 libstdc++: Add workaround for fs::path constraint recursion [PR106201] This works around a compiler bug where overload resolution attempts implicit conversion to path in order to call a function with a path& parameter. Such conversion would produce a prvalue, which would not be able to bind to the lvalue reference anyway. Attempting to check the conversion causes a constraint recursion because the arguments to the path constructor are checked to see if they're iterators, which checks if they're swappable, which tries to use the swap function that triggered the conversion in the first place. This replaces the swap function with an abbreviated function template that is constrained with same_as auto& so that the invalid conversion is never considered. libstdc++-v3/ChangeLog: PR libstdc++/106201 * include/bits/fs_path.h (filesystem::swap(path&, path&)): Replace with abbreviated function template. * include/experimental/bits/fs_path.h (filesystem::swap): Likewise. * testsuite/27_io/filesystem/iterators/106201.cc: New test. * testsuite/experimental/filesystem/iterators/106201.cc: New test. Diff: --- libstdc++-v3/include/bits/fs_path.h | 7 +++++++ libstdc++-v3/include/experimental/bits/fs_path.h | 9 ++++++++- .../testsuite/27_io/filesystem/iterators/106201.cc | 14 ++++++++++++++ .../testsuite/experimental/filesystem/iterators/106201.cc | 14 ++++++++++++++ 4 files changed, 43 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/include/bits/fs_path.h b/libstdc++-v3/include/bits/fs_path.h index 65682c2a185..1b4a1b69f37 100644 --- 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 auto& __lhs, same_as 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; diff --git a/libstdc++-v3/include/experimental/bits/fs_path.h b/libstdc++-v3/include/experimental/bits/fs_path.h index a493e17a37e..ba6acb2158d 100644 --- a/libstdc++-v3/include/experimental/bits/fs_path.h +++ b/libstdc++-v3/include/experimental/bits/fs_path.h @@ -537,7 +537,14 @@ namespace __detail /// @relates std::experimental::filesystem::path @{ /// Swap overload for paths - inline void swap(path& __lhs, path& __rhs) noexcept { __lhs.swap(__rhs); } +#if __cpp_concepts >= 201907L + // Workaround for PR libstdc++/106201 + inline void + swap(same_as auto& __lhs, same_as auto& __rhs) noexcept + { __lhs.swap(__rhs); } +#else + inline void swap(path& __lhs, path& __rhs) noexcept { __lhs.swap(__rhs); } +#endif /// Compute a hash value for a path size_t hash_value(const path& __p) noexcept; diff --git a/libstdc++-v3/testsuite/27_io/filesystem/iterators/106201.cc b/libstdc++-v3/testsuite/27_io/filesystem/iterators/106201.cc new file mode 100644 index 00000000000..c5fefd9ac3f --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/iterators/106201.cc @@ -0,0 +1,14 @@ +// { dg-options "-std=gnu++20" } +// { dg-do compile { target c++20 } } +// { dg-require-filesystem-ts "" } + +// PR libstdc++/106201 constraint recursion in path(Source const&) constructor. + +#include +#include +#include +namespace fs = std::filesystem; +using I = std::counted_iterator; +static_assert( std::swappable ); +using R = std::counted_iterator; +static_assert( std::swappable ); diff --git a/libstdc++-v3/testsuite/experimental/filesystem/iterators/106201.cc b/libstdc++-v3/testsuite/experimental/filesystem/iterators/106201.cc new file mode 100644 index 00000000000..017b72ef5f6 --- /dev/null +++ b/libstdc++-v3/testsuite/experimental/filesystem/iterators/106201.cc @@ -0,0 +1,14 @@ +// { dg-options "-std=gnu++20" } +// { dg-do compile { target c++20 } } +// { dg-require-filesystem-ts "" } + +// PR libstdc++/106201 constraint recursion in path(Source const&) constructor. + +#include +#include +#include +namespace fs = std::experimental::filesystem; +using I = std::counted_iterator; +static_assert( std::swappable ); +using R = std::counted_iterator; +static_assert( std::swappable );