summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/27_io/filesystem/path
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2019-04-05 17:56:14 +0100
committerJonathan Wakely <redi@gcc.gnu.org>2019-04-05 17:56:14 +0100
commitd96f11a2720c8ddfc3d181b181cfaadd888323cd (patch)
treeafbf6b6816e29fd29cd900906f354e82fde3df91 /libstdc++-v3/testsuite/27_io/filesystem/path
parent10f26de9155b71a2bd5055060004420939cf7a2d (diff)
Make filesystem::path safe for self assignment
The standard says "If *this and p are the same object, has no effect." Previously we ended up clearing the path. * include/bits/fs_path.h (path::operator=(path&&)): Check for self assignment. * src/c++17/fs_path.cc (path::operator=(const path&)): Likewise. * testsuite/27_io/filesystem/path/assign/copy.cc: Test self assignment. From-SVN: r270171
Diffstat (limited to 'libstdc++-v3/testsuite/27_io/filesystem/path')
-rw-r--r--libstdc++-v3/testsuite/27_io/filesystem/path/assign/copy.cc18
1 files changed, 18 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/assign/copy.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/assign/copy.cc
index 6c24e3ae7b9..775dbffad36 100644
--- a/libstdc++-v3/testsuite/27_io/filesystem/path/assign/copy.cc
+++ b/libstdc++-v3/testsuite/27_io/filesystem/path/assign/copy.cc
@@ -20,6 +20,7 @@
#include <filesystem>
#include <testsuite_fs.h>
+#include <testsuite_hooks.h>
using std::filesystem::path;
using __gnu_test::compare_paths;
@@ -47,9 +48,26 @@ test02()
}
}
+void
+test03()
+{
+ // self assignment should have no effect
+ const path orig = "foo/bar/baz";
+ path p = orig;
+ const auto ptr1 = p.c_str();
+ const auto ptr2 = p.begin()->c_str();
+ p = std::move(p);
+ __gnu_test::compare_paths(p, orig);
+ p = p;
+ __gnu_test::compare_paths(p, orig);
+ VERIFY( ptr1 == p.c_str() );
+ VERIFY( ptr2 == p.begin()->c_str() );
+}
+
int
main()
{
test01();
test02();
+ test03();
}