From: Jonathan Wakely Date: Tue, 10 May 2016 15:39:20 +0000 (+0100) Subject: Test begin and end functions for directory iterators X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=7f99d40a99b24026874887aff0cd269370e082f3;p=gcc.git Test begin and end functions for directory iterators * 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 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 614f192fa17..fdcb9cae2be 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,11 @@ 2016-05-10 Jonathan Wakely + * 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. diff --git a/libstdc++-v3/include/experimental/bits/fs_dir.h b/libstdc++-v3/include/experimental/bits/fs_dir.h index 011d3981622..70a95ebfe66 100644 --- a/libstdc++-v3/include/experimental/bits/fs_dir.h +++ b/libstdc++-v3/include/experimental/bits/fs_dir.h @@ -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, diff --git a/libstdc++-v3/testsuite/experimental/filesystem/iterators/directory_iterator.cc b/libstdc++-v3/testsuite/experimental/filesystem/iterators/directory_iterator.cc index ce9f437b0df..ffd97ce19d2 100644 --- a/libstdc++-v3/testsuite/experimental/filesystem/iterators/directory_iterator.cc +++ b/libstdc++-v3/testsuite/experimental/filesystem/iterators/directory_iterator.cc @@ -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(); } diff --git a/libstdc++-v3/testsuite/experimental/filesystem/iterators/recursive_directory_iterator.cc b/libstdc++-v3/testsuite/experimental/filesystem/iterators/recursive_directory_iterator.cc index fb4c31ec9ad..b44ff3f9e9b 100644 --- a/libstdc++-v3/testsuite/experimental/filesystem/iterators/recursive_directory_iterator.cc +++ b/libstdc++-v3/testsuite/experimental/filesystem/iterators/recursive_directory_iterator.cc @@ -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(); }