Fix path::iterator post-increment and post-decrement
authorJonathan Wakely <jwakely@redhat.com>
Thu, 19 Oct 2017 13:57:06 +0000 (14:57 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Thu, 19 Oct 2017 13:57:06 +0000 (14:57 +0100)
* 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
libstdc++-v3/include/experimental/bits/fs_path.h
libstdc++-v3/testsuite/experimental/filesystem/path/itr/traversal.cc

index 72d9b77001bda03d7a25e8f09dba5e62cb3eb7bc..76c87d65e74b8babbe81fe4835c130afed6ea268 100644 (file)
@@ -1,5 +1,10 @@
 2017-10-19  Jonathan Wakely  <jwakely@redhat.com>
 
+       * 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.
 
index cde3897b8e5226aa13508de219e991e2309772b8..9121439b7f20e6ee59f8a9a7bf57e93610c8eb86 100644 (file)
@@ -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); }
index bc1091476b5761eded2bc19a8b04fa1f9f33cfcf..dbb4d46796dc38a1d2c0c3ac9eba2b92967b5a7c 100644 (file)
@@ -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();
 }