From f2cd34d401db20648e123e2489a4675bce9794e1 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Mon, 23 Oct 2017 18:47:05 +0100 Subject: [PATCH] Fix path::iterator post-increment and post-decrement Backport from mainline 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. From-SVN: r254017 --- libstdc++-v3/ChangeLog | 10 ++++++++++ .../include/experimental/bits/fs_path.h | 4 ++-- .../filesystem/path/itr/traversal.cc | 18 ++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index f803618da6f1..12f5fb9de017 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,13 @@ +2017-10-23 Jonathan Wakely + + Backport from mainline + 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. + 2017-09-20 Jonathan Wakely Backport from mainline diff --git a/libstdc++-v3/include/experimental/bits/fs_path.h b/libstdc++-v3/include/experimental/bits/fs_path.h index 153d34557eef..243b46c7b9c8 100644 --- a/libstdc++-v3/include/experimental/bits/fs_path.h +++ b/libstdc++-v3/include/experimental/bits/fs_path.h @@ -724,10 +724,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 47f9f4343c04..d822ed204eec 100644 --- a/libstdc++-v3/testsuite/experimental/filesystem/path/itr/traversal.cc +++ b/libstdc++-v3/testsuite/experimental/filesystem/path/itr/traversal.cc @@ -78,9 +78,27 @@ 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 ); + --iter; + iter2--; + VERIFY( iter2 == iter ); + } +} + int main() { test01(); test02(); + test03(); } -- 2.47.2