Test begin and end functions for directory iterators
authorJonathan Wakely <jwakely@redhat.com>
Tue, 10 May 2016 15:39:20 +0000 (16:39 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Tue, 10 May 2016 15:39:20 +0000 (16:39 +0100)
* include/experimental/bits/fs_dir.h (begin, end): Add noexcept.
* testsuite/experimental/filesystem/iterators/directory_iterator.cc:
Test begin and end functions.
* testsuite/experimental/filesystem/iterators/
recursive_directory_iterator.cc: Likewise.

From-SVN: r236085

libstdc++-v3/ChangeLog
libstdc++-v3/include/experimental/bits/fs_dir.h
libstdc++-v3/testsuite/experimental/filesystem/iterators/directory_iterator.cc
libstdc++-v3/testsuite/experimental/filesystem/iterators/recursive_directory_iterator.cc

index 614f192fa17fc47d26293a31e0e0c51dde692f54..fdcb9cae2beb34cd08dbdf5f53f97569b50147bb 100644 (file)
@@ -1,5 +1,11 @@
 2016-05-10  Jonathan Wakely  <jwakely@redhat.com>
 
+       * include/experimental/bits/fs_dir.h (begin, end): Add noexcept.
+       * testsuite/experimental/filesystem/iterators/directory_iterator.cc:
+       Test begin and end functions.
+       * testsuite/experimental/filesystem/iterators/
+       recursive_directory_iterator.cc: Likewise.
+
        PR libstdc++/71038
        * src/filesystem/ops.cc (do_copy_file): Fix backwards conditions.
        * testsuite/experimental/filesystem/operations/copy_file.cc: New test.
index 011d3981622411eb4373c144b2b9f680f46843c4..70a95ebfe66b553f502db02c372e04226f64722a 100644 (file)
@@ -235,10 +235,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
   };
 
   inline directory_iterator
-  begin(directory_iterator __iter) { return __iter; }
+  begin(directory_iterator __iter) noexcept
+  { return __iter; }
 
   inline directory_iterator
-  end(directory_iterator) { return directory_iterator(); }
+  end(directory_iterator) noexcept
+  { return directory_iterator(); }
 
   inline bool
   operator==(const directory_iterator& __lhs, const directory_iterator& __rhs)
@@ -327,10 +329,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
   };
 
   inline recursive_directory_iterator
-  begin(recursive_directory_iterator __iter) { return __iter; }
+  begin(recursive_directory_iterator __iter) noexcept
+  { return __iter; }
 
   inline recursive_directory_iterator
-  end(recursive_directory_iterator) { return recursive_directory_iterator(); }
+  end(recursive_directory_iterator) noexcept
+  { return recursive_directory_iterator(); }
 
   inline bool
   operator==(const recursive_directory_iterator& __lhs,
index ce9f437b0df06080e40859779d9fc094e045a49e..ffd97ce19d25ec8bf4f18876044d755c65e310b9 100644 (file)
@@ -113,10 +113,36 @@ test03()
   remove_all(p, ec);
 }
 
+void
+test04()
+{
+  bool test __attribute__((unused)) = false;
+
+  const fs::directory_iterator it;
+  VERIFY( it == fs::directory_iterator() );
+}
+
+void
+test05()
+{
+  bool test __attribute__((unused)) = false;
+
+  auto p = __gnu_test::nonexistent_path();
+  create_directory(p);
+  create_directory_symlink(p, p / "l");
+  fs::directory_iterator it(p), endit;
+  VERIFY( begin(it) == it );
+  static_assert( noexcept(begin(it)), "begin is noexcept" );
+  VERIFY( end(it) == endit );
+  static_assert( noexcept(end(it)), "end is noexcept" );
+}
+
 int
 main()
 {
   test01();
   test02();
   test03();
+  test04();
+  test05();
 }
index fb4c31ec9add7e33dba9898e1716dcc97f6706d9..b44ff3f9e9bdde188c9bc8bbb2b86097aa547f93 100644 (file)
@@ -153,6 +153,21 @@ test04()
   VERIFY( it == fs::recursive_directory_iterator() );
 }
 
+void
+test05()
+{
+  bool test __attribute__((unused)) = false;
+
+  auto p = __gnu_test::nonexistent_path();
+  create_directory(p);
+  create_directory_symlink(p, p / "l");
+  fs::recursive_directory_iterator it(p), endit;
+  VERIFY( begin(it) == it );
+  static_assert( noexcept(begin(it)), "begin is noexcept" );
+  VERIFY( end(it) == endit );
+  static_assert( noexcept(end(it)), "end is noexcept" );
+}
+
 int
 main()
 {
@@ -160,4 +175,5 @@ main()
   test02();
   test03();
   test04();
+  test05();
 }