summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/27_io/filesystem/path
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2021-06-11 19:18:11 +0100
committerJonathan Wakely <jwakely@redhat.com>2021-06-11 19:18:11 +0100
commit1e690757d30775ed340a368b9a9463b2ad68de01 (patch)
tree4e7f202016e8d39dc2c09b19c54ebad3d3dc3908 /libstdc++-v3/testsuite/27_io/filesystem/path
parent68f46862d33707450bdf70cfddd91ae2a12527a8 (diff)
libstdc++: Fix filesystem::path comparisons for C++23
In C++23 there is a basic_string_view(Range&&) constructor, which is constrained to take a range (specifically, a contiguous_range). When the filesystem::path comparison operators call lhs.compare(rhs) the overload taking a string_view is considered, which means checking whether path satisfies the range concept. That satisfaction result changes depending whether path::iterator is complete, which is ill-formed; no diagnostic required. To avoid the problem, this change ensures that the overload resolution is performed in a context where path::iterator is complete and the range concept is satisfied. (The result of overload resolution is always that the compare(const path&) overload is the best match, but we still have to consider the compare(basic_string_view<value_type>) one to decide if it even participates in overload resolution). For std::filesystem::path we can't define the comparison operators later in the file, because they are hidden friends, so a new helper is introduced that gets defined when everything else is complete. For std::experimental::filesystem::path we can just move the definitions of the comparison operators later in the file. Signed-off-by: Jonathan Wakely <jwakely@redhat.com> libstdc++-v3/ChangeLog: * include/bits/fs_path.h (operator==, operator<=>): Use new _S_compare function. (path::_S_compare): New function to call path::compare in a context where path::iterator is complete. * include/experimental/bits/fs_path.h (operator<, operator==): Define after path::iterator is complete. * testsuite/27_io/filesystem/path/native/conv_c++23.cc: New test. * testsuite/experimental/filesystem/path/native/conv_c++23.cc: New test.
Diffstat (limited to 'libstdc++-v3/testsuite/27_io/filesystem/path')
-rw-r--r--libstdc++-v3/testsuite/27_io/filesystem/path/native/conv_c++23.cc12
1 files changed, 12 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/native/conv_c++23.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/native/conv_c++23.cc
new file mode 100644
index 00000000000..b4efed2bd47
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/filesystem/path/native/conv_c++23.cc
@@ -0,0 +1,12 @@
+// { dg-options "-std=gnu++23" }
+// { dg-do compile { target c++23 } }
+
+#include <filesystem>
+
+void
+test01()
+{
+ using std::filesystem::path;
+ path p;
+ path::string_type s(p);
+}