diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2019-05-22 23:14:34 +0100 |
---|---|---|
committer | Jonathan Wakely <redi@gcc.gnu.org> | 2019-05-22 23:14:34 +0100 |
commit | f9b22a0c24235d72cf78e70c64bcf695f1f6b3f7 (patch) | |
tree | 5e8c520f2c788fa9b41b914b291fe2ba461f955b | |
parent | 7039cebfa8da3e6309bf1792ca063497257edcd8 (diff) | |
download | gcc-f9b22a0c24235d72cf78e70c64bcf695f1f6b3f7.zip gcc-f9b22a0c24235d72cf78e70c64bcf695f1f6b3f7.tar.gz gcc-f9b22a0c24235d72cf78e70c64bcf695f1f6b3f7.tar.bz2 |
PR libstdc++/90557 fix path assignment that alters source
PR libstdc++/90557
* src/c++17/fs_path.cc (path::_List::operator=(const _List&)): Fix
reversed arguments to uninitialized_copy_n.
* testsuite/27_io/filesystem/path/assign/copy.cc: Check that source
is unchanged by copy assignment.
* testsuite/util/testsuite_fs.h (compare_paths): Use std::equal to
compare path components.
From-SVN: r271527
-rw-r--r-- | libstdc++-v3/ChangeLog | 8 | ||||
-rw-r--r-- | libstdc++-v3/src/c++17/fs_path.cc | 4 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/27_io/filesystem/path/assign/copy.cc | 15 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/util/testsuite_fs.h | 10 |
4 files changed, 33 insertions, 4 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index cf9d86a..d7faf93 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,13 @@ 2019-05-22 Jonathan Wakely <jwakely@redhat.com> + PR libstdc++/90557 + * src/c++17/fs_path.cc (path::_List::operator=(const _List&)): Fix + reversed arguments to uninitialized_copy_n. + * testsuite/27_io/filesystem/path/assign/copy.cc: Check that source + is unchanged by copy assignment. + * testsuite/util/testsuite_fs.h (compare_paths): Use std::equal to + compare path components. + PR libstdc++/77691 * include/experimental/memory_resource: Add system header pragma and do not define anything unless compiled as C++14 or later. diff --git a/libstdc++-v3/src/c++17/fs_path.cc b/libstdc++-v3/src/c++17/fs_path.cc index 605f62c..8e01bf5 100644 --- a/libstdc++-v3/src/c++17/fs_path.cc +++ b/libstdc++-v3/src/c++17/fs_path.cc @@ -278,8 +278,8 @@ path::_List::operator=(const _List& other) to[i]._M_pathname.reserve(from[i]._M_pathname.length()); if (newsize > oldsize) { - std::uninitialized_copy_n(to + oldsize, newsize - oldsize, - from + oldsize); + std::uninitialized_copy_n(from + oldsize, newsize - oldsize, + to + oldsize); impl->_M_size = newsize; } else if (newsize < oldsize) 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 775dbff..6aa25ae 100644 --- a/libstdc++-v3/testsuite/27_io/filesystem/path/assign/copy.cc +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/assign/copy.cc @@ -64,10 +64,25 @@ test03() VERIFY( ptr2 == p.begin()->c_str() ); } +void +test04() +{ + // PR libstdc++/90557 + path p1 = "a/b/c"; + const path p2 = "d/e"; + const path p3 = p2; + p1.clear(); + p1 = p2; + __gnu_test::compare_paths(p1, p2); + __gnu_test::compare_paths(p1, p3); + __gnu_test::compare_paths(p2, p3); +} + int main() { test01(); test02(); test03(); + test04(); } diff --git a/libstdc++-v3/testsuite/util/testsuite_fs.h b/libstdc++-v3/testsuite/util/testsuite_fs.h index baba90e..b2a5ee6 100644 --- a/libstdc++-v3/testsuite/util/testsuite_fs.h +++ b/libstdc++-v3/testsuite/util/testsuite_fs.h @@ -30,6 +30,7 @@ namespace test_fs = std::filesystem; #include <experimental/filesystem> namespace test_fs = std::experimental::filesystem; #endif +#include <algorithm> #include <fstream> #include <string> #include <cstdio> @@ -62,10 +63,15 @@ namespace __gnu_test PATH_CHK( p1, p2, is_relative ); auto d1 = std::distance(p1.begin(), p1.end()); auto d2 = std::distance(p2.begin(), p2.end()); - if( d1 != d2 ) + if (d1 != d2) throw test_fs::filesystem_error( - "distance(begin, end)", p1, p2, + "distance(begin1, end1) != distance(begin2, end2)", p1, p2, std::make_error_code(std::errc::invalid_argument) ); + if (!std::equal(p1.begin(), p1.end(), p2.begin(), p2.end())) + throw test_fs::filesystem_error( + "!equal(begin1, end1, begin2, end2)", p1, p2, + std::make_error_code(std::errc::invalid_argument) ); + } const std::string test_paths[] = { |