I made a dumb mistake in the post-inc and post-dec operators for the path::iterator type, forgetting that _M_cur is sometimes null (for a single-element path).
* 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. Tested powerpc64le-linux, committed to trunk. It's too late to fix this on the gcc-5 branch but I'll backport it to gcc-6 and gcc-7 soon.
commit 1c773ea81a8781dfbb4381a496aa5bab5bd623de Author: Jonathan Wakely <jwak...@redhat.com> Date: Wed Oct 18 02:47:24 2017 +0100 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. diff --git a/libstdc++-v3/include/experimental/bits/fs_path.h b/libstdc++-v3/include/experimental/bits/fs_path.h index cde3897b8e5..9121439b7f2 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 bc1091476b5..dbb4d46796d 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(); }