From 551124d5613673c70b92aff884430476f04684e1 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Thu, 19 Oct 2017 14:57:06 +0100 Subject: Fix path::iterator post-increment and post-decrement * include/experimental/bits/fs_path.h (path::iterator++(int)) (path::iterator--(int)): Fix for paths with only one component. * testsuite/experimental/filesystem/path/itr/traversal.cc: Test post-increment and post-decrement. From-SVN: r253896 --- libstdc++-v3/ChangeLog | 5 +++++ libstdc++-v3/include/experimental/bits/fs_path.h | 4 ++-- .../experimental/filesystem/path/itr/traversal.cc | 19 +++++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 72d9b77..76c87d65 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,10 @@ 2017-10-19 Jonathan Wakely + * include/experimental/bits/fs_path.h (path::iterator++(int)) + (path::iterator--(int)): Fix for paths with only one component. + * testsuite/experimental/filesystem/path/itr/traversal.cc: Test + post-increment and post-decrement. + * doc/xml/manual/status_cxx2017.xml: Update references to C++17 section numbers. diff --git a/libstdc++-v3/include/experimental/bits/fs_path.h b/libstdc++-v3/include/experimental/bits/fs_path.h index cde3897..9121439 100644 --- a/libstdc++-v3/include/experimental/bits/fs_path.h +++ b/libstdc++-v3/include/experimental/bits/fs_path.h @@ -725,10 +725,10 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 pointer operator->() const { return std::__addressof(**this); } iterator& operator++(); - iterator operator++(int) { auto __tmp = *this; ++_M_cur; return __tmp; } + iterator operator++(int) { auto __tmp = *this; ++*this; return __tmp; } iterator& operator--(); - iterator operator--(int) { auto __tmp = *this; --_M_cur; return __tmp; } + iterator operator--(int) { auto __tmp = *this; --*this; return __tmp; } friend bool operator==(const iterator& __lhs, const iterator& __rhs) { return __lhs._M_equals(__rhs); } diff --git a/libstdc++-v3/testsuite/experimental/filesystem/path/itr/traversal.cc b/libstdc++-v3/testsuite/experimental/filesystem/path/itr/traversal.cc index bc10914..dbb4d46 100644 --- a/libstdc++-v3/testsuite/experimental/filesystem/path/itr/traversal.cc +++ b/libstdc++-v3/testsuite/experimental/filesystem/path/itr/traversal.cc @@ -79,9 +79,28 @@ test02() } } +void +test03() +{ + path paths[] = { "single", "multiple/elements" }; + for (const path& p : paths) + for (auto iter = p.begin(); iter != p.end(); ++iter) + { + auto iter2 = iter; + ++iter; + iter2++; + VERIFY( iter2 == iter ); + auto iter3 = iter; + --iter3; + iter2--; + VERIFY( iter2 == iter3 ); + } +} + int main() { test01(); test02(); + test03(); } -- cgit v1.1