diff options
Diffstat (limited to 'libstdc++-v3/testsuite')
153 files changed, 7520 insertions, 390 deletions
diff --git a/libstdc++-v3/testsuite/18_support/byte/requirements.cc b/libstdc++-v3/testsuite/18_support/byte/requirements.cc index 4cb05df0405..74c8b64d6ce 100644 --- a/libstdc++-v3/testsuite/18_support/byte/requirements.cc +++ b/libstdc++-v3/testsuite/18_support/byte/requirements.cc @@ -20,6 +20,12 @@ #include <cstddef> +#ifndef __cpp_lib_byte +# error "Feature-test macro for byte missing" +#elif __cpp_lib_byte != 201603 +# error "Feature-test macro for byte has wrong value" +#endif + static_assert( sizeof(std::byte) == sizeof(unsigned char) ); static_assert( alignof(std::byte) == alignof(unsigned char) ); diff --git a/libstdc++-v3/testsuite/18_support/headers/limits/synopsis.cc b/libstdc++-v3/testsuite/18_support/headers/limits/synopsis.cc index e298374920b..91fdf37be53 100644 --- a/libstdc++-v3/testsuite/18_support/headers/limits/synopsis.cc +++ b/libstdc++-v3/testsuite/18_support/headers/limits/synopsis.cc @@ -1,4 +1,5 @@ // { dg-do compile } +// { dg-require-normal-namespace "" } // Copyright (C) 2007-2017 Free Software Foundation, Inc. // diff --git a/libstdc++-v3/testsuite/20_util/duration/arithmetic/constexpr_c++17.cc b/libstdc++-v3/testsuite/20_util/duration/arithmetic/constexpr_c++17.cc index 438d50afddf..0ba1b8cc706 100644 --- a/libstdc++-v3/testsuite/20_util/duration/arithmetic/constexpr_c++17.cc +++ b/libstdc++-v3/testsuite/20_util/duration/arithmetic/constexpr_c++17.cc @@ -20,6 +20,13 @@ #include <chrono> #include <testsuite_common_types.h> + +#ifndef __cpp_lib_chrono +# error "Feature-test macro for constexpr <chrono> missing" +#elif __cpp_lib_chrono != 201611 +# error "Feature-test macro for constexpr <chrono> has wrong value" +#endif + constexpr auto test_operators() { std::chrono::nanoseconds d1 { 1 }; diff --git a/libstdc++-v3/testsuite/20_util/endian/1.cc b/libstdc++-v3/testsuite/20_util/endian/1.cc new file mode 100644 index 00000000000..2720c5edcdb --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/endian/1.cc @@ -0,0 +1,36 @@ +// Copyright (C) 2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +#include <type_traits> + +static_assert( std::is_enum_v<std::endian> ); +static_assert( std::endian::little != std::endian::big ); +static_assert( std::endian::native == std::endian::big + || std::endian::native == std::endian::little ); + +namespace gnu { + int little, big, native; +} + +using namespace std; +using namespace gnu; + +// std::endian is a scoped-enum so these should refer to gnu::native etc. +int test = little + big + native; diff --git a/libstdc++-v3/testsuite/20_util/from_chars/requirements.cc b/libstdc++-v3/testsuite/20_util/from_chars/requirements.cc index 00b7d875664..6afc918909a 100644 --- a/libstdc++-v3/testsuite/20_util/from_chars/requirements.cc +++ b/libstdc++-v3/testsuite/20_util/from_chars/requirements.cc @@ -17,6 +17,7 @@ // { dg-options "-std=gnu++17" } // { dg-do compile { target c++17 } } +// { dg-require-normal-namespace "" } #include <charconv> diff --git a/libstdc++-v3/testsuite/20_util/headers/functional/synopsis.cc b/libstdc++-v3/testsuite/20_util/headers/functional/synopsis.cc index 466d3d47965..c001daa955a 100644 --- a/libstdc++-v3/testsuite/20_util/headers/functional/synopsis.cc +++ b/libstdc++-v3/testsuite/20_util/headers/functional/synopsis.cc @@ -1,4 +1,5 @@ // { dg-do compile } +// { dg-require-normal-namespace "" } // Copyright (C) 2007-2017 Free Software Foundation, Inc. // diff --git a/libstdc++-v3/testsuite/20_util/headers/memory/synopsis.cc b/libstdc++-v3/testsuite/20_util/headers/memory/synopsis.cc index adf5f4829b9..95f42acb7cf 100644 --- a/libstdc++-v3/testsuite/20_util/headers/memory/synopsis.cc +++ b/libstdc++-v3/testsuite/20_util/headers/memory/synopsis.cc @@ -1,4 +1,5 @@ // { dg-do compile } +// { dg-require-normal-namespace "" } // Copyright (C) 2007-2017 Free Software Foundation, Inc. // diff --git a/libstdc++-v3/testsuite/20_util/headers/utility/synopsis.cc b/libstdc++-v3/testsuite/20_util/headers/utility/synopsis.cc index 71f1903f2d5..95308139d5d 100644 --- a/libstdc++-v3/testsuite/20_util/headers/utility/synopsis.cc +++ b/libstdc++-v3/testsuite/20_util/headers/utility/synopsis.cc @@ -1,4 +1,5 @@ // { dg-do compile } +// { dg-require-normal-namespace "" } // Copyright (C) 2007-2017 Free Software Foundation, Inc. // diff --git a/libstdc++-v3/testsuite/20_util/pair/astuple/get.cc b/libstdc++-v3/testsuite/20_util/pair/astuple/get.cc index 80939741f6c..e81af3b2f33 100644 --- a/libstdc++-v3/testsuite/20_util/pair/astuple/get.cc +++ b/libstdc++-v3/testsuite/20_util/pair/astuple/get.cc @@ -27,4 +27,9 @@ void test01() float&& pfirst __attribute__((unused)) = std::get<0>(std::move(p)); int&& psecond __attribute__((unused)) = std::get<1>(std::move(p)); + + const std::pair<float, int> cp; + + const float&& cpfirst __attribute__((unused)) = std::get<0>(std::move(cp)); + const int&& cpsecond __attribute__((unused)) = std::get<1>(std::move(cp)); } diff --git a/libstdc++-v3/testsuite/20_util/pair/astuple/get_by_type.cc b/libstdc++-v3/testsuite/20_util/pair/astuple/get_by_type.cc index 8d8bf0efe94..1e70fbcf43f 100644 --- a/libstdc++-v3/testsuite/20_util/pair/astuple/get_by_type.cc +++ b/libstdc++-v3/testsuite/20_util/pair/astuple/get_by_type.cc @@ -25,4 +25,11 @@ void test01() float&& pfirst __attribute__((unused)) = std::get<float>(std::move(p)); int&& psecond __attribute__((unused)) = std::get<int>(std::move(p)); + + const std::pair<float, int> cp; + + const float&& cpfirst __attribute__((unused)) = + std::get<float>(std::move(cp)); + const int&& cpsecond __attribute__((unused)) = + std::get<int>(std::move(cp)); } diff --git a/libstdc++-v3/testsuite/20_util/specialized_algorithms/memory_management_tools/1.cc b/libstdc++-v3/testsuite/20_util/specialized_algorithms/memory_management_tools/1.cc index 39d3e76ee82..d118dd18ce9 100644 --- a/libstdc++-v3/testsuite/20_util/specialized_algorithms/memory_management_tools/1.cc +++ b/libstdc++-v3/testsuite/20_util/specialized_algorithms/memory_management_tools/1.cc @@ -19,8 +19,8 @@ #include <memory> #include <testsuite_hooks.h> +#include <testsuite_iterators.h> #include <string> -#include <array> #include <vector> #include <sstream> @@ -56,36 +56,42 @@ struct ThrowAfterN DelCount dc; }; +template<typename T> + using FwdIteratorRange + = __gnu_test::test_container<T, __gnu_test::forward_iterator_wrapper>; + void test01() { char test_data[] = "123456"; - std::uninitialized_default_construct(std::begin(test_data), - std::end(test_data)); + FwdIteratorRange<char> r(test_data); + std::uninitialized_default_construct(std::begin(r), std::end(r)); VERIFY(std::string(test_data) == "123456"); } void test02() { char test_data[] = "123456"; - std::uninitialized_value_construct(std::begin(test_data), - std::end(test_data)); + FwdIteratorRange<char> r(test_data); + std::uninitialized_value_construct(std::begin(r), std::end(r)); VERIFY(std::string(test_data, 6) == std::string("\0\0\0\0\0\0", 6)); } void test03() { char test_data[] = "123456"; - auto end = std::uninitialized_default_construct_n(std::begin(test_data), 6); + FwdIteratorRange<char> r(test_data); + auto end = std::uninitialized_default_construct_n(std::begin(r), 6); VERIFY(std::string(test_data) == "123456"); - VERIFY( end == test_data + 6 ); + VERIFY( end == std::next(r.begin(), 6) ); } void test04() { char test_data[] = "123456"; - auto end = std::uninitialized_value_construct_n(std::begin(test_data), 5); + FwdIteratorRange<char> r(test_data); + auto end = std::uninitialized_value_construct_n(std::begin(r), 5); VERIFY(std::string(test_data, 6) == std::string("\0\0\0\0\0" "6", 6)); - VERIFY( end == test_data + 5 ); + VERIFY( end == std::next(r.begin(), 5) ); } void test05() @@ -122,33 +128,43 @@ void test07() free(x); } +struct MoveOnly +{ + MoveOnly() : val(-1) { } + MoveOnly(MoveOnly&& m) : val(m.val) { m.val = -1; } + int val; +}; + void test08() { - std::vector<std::unique_ptr<int>> source; - for (int i = 0; i < 10; ++i) source.push_back(std::make_unique<int>(i)); - std::unique_ptr<int>* target = - (std::unique_ptr<int>*)malloc(sizeof(std::unique_ptr<int>)*10); - std::uninitialized_move(source.begin(), source.end(), target); - for (const auto& x : source) VERIFY(!x); - for (int i = 0; i < 10; ++i) VERIFY(bool(*(target+i))); - auto end = std::destroy_n(target, 10); - VERIFY( end == target + 10 ); + MoveOnly source[10]; + for (int i = 0; i < 10; ++i) source[i].val = i; + FwdIteratorRange<MoveOnly> src(source); + MoveOnly* target = (MoveOnly*)malloc(sizeof(MoveOnly)*10); + FwdIteratorRange<MoveOnly> tgt(target, target+10); + auto end = std::uninitialized_move(src.begin(), src.end(), tgt.begin()); + VERIFY( end == std::next(tgt.begin(), 10) ); + for (const auto& x : source) VERIFY( x.val == -1 ); + for (int i = 0; i < 10; ++i) VERIFY( target[i].val == i ); + auto end2 = std::destroy_n(tgt.begin(), 10); + VERIFY( end2 == std::next(tgt.begin(), 10) ); free(target); } void test09() { - std::vector<std::unique_ptr<int>> source; - for (int i = 0; i < 10; ++i) source.push_back(std::make_unique<int>(i)); - std::unique_ptr<int>* target = - (std::unique_ptr<int>*)malloc(sizeof(std::unique_ptr<int>)*10); - auto end = std::uninitialized_move_n(source.begin(), 10, target); - VERIFY( end.first == source.begin() + 10 ); - VERIFY( end.second == target + 10 ); - for (const auto& x : source) VERIFY(!x); - for (int i = 0; i < 10; ++i) VERIFY(bool(*(target+i))); - auto end2 = std::destroy_n(target, 10); - VERIFY( end2 == target + 10 ); + MoveOnly source[10]; + for (int i = 0; i < 10; ++i) source[i].val = i; + FwdIteratorRange<MoveOnly> src(source); + MoveOnly* target = (MoveOnly*)malloc(sizeof(MoveOnly)*10); + FwdIteratorRange<MoveOnly> tgt(target, target+10); + auto end = std::uninitialized_move_n(src.begin(), 10, tgt.begin()); + VERIFY( end.first == std::next(src.begin(), 10) ); + VERIFY( end.second == std::next(tgt.begin(), 10) ); + for (const auto& x : source) VERIFY( x.val == -1 ); + for (int i = 0; i < 10; ++i) VERIFY( target[i].val == i ); + auto end2 = std::destroy_n(tgt.begin(), 10); + VERIFY( end2 == std::next(tgt.begin(), 10) ); free(target); } @@ -156,7 +172,8 @@ void test10() { char* x = (char*)malloc(sizeof(char)*10); for (int i = 0; i < 10; ++i) new (x+i) char; - std::destroy(x, x+10); + FwdIteratorRange<char> r(x, x+10); + std::destroy(r.begin(), r.end()); free(x); } @@ -164,8 +181,9 @@ void test11() { char* x = (char*)malloc(sizeof(char)*10); for (int i = 0; i < 10; ++i) new (x+i) char; - auto end = std::destroy_n(x, 10); - VERIFY( end == x + 10 ); + FwdIteratorRange<char> r(x, x+10); + auto end = std::destroy_n(r.begin(), 10); + VERIFY( end == std::next(r.begin(), 10) ); free(x); } diff --git a/libstdc++-v3/testsuite/20_util/to_chars/requirements.cc b/libstdc++-v3/testsuite/20_util/to_chars/requirements.cc index d50588bd902..4c13d8ae71a 100644 --- a/libstdc++-v3/testsuite/20_util/to_chars/requirements.cc +++ b/libstdc++-v3/testsuite/20_util/to_chars/requirements.cc @@ -17,6 +17,7 @@ // { dg-options "-std=gnu++17" } // { dg-do compile { target c++17 } } +// { dg-require-normal-namespace "" } #include <charconv> diff --git a/libstdc++-v3/testsuite/20_util/tuple/element_access/get2.cc b/libstdc++-v3/testsuite/20_util/tuple/element_access/get2.cc index 14bdb0c6b1f..bc0f1bc899b 100644 --- a/libstdc++-v3/testsuite/20_util/tuple/element_access/get2.cc +++ b/libstdc++-v3/testsuite/20_util/tuple/element_access/get2.cc @@ -37,4 +37,19 @@ void test01() short&& t3one __attribute__((unused)) = std::get<0>(std::move(t3)); int&& t3two __attribute__((unused)) = std::get<1>(std::move(t3)); double&& t3thr __attribute__((unused)) = std::get<2>(std::move(t3)); + + const std::tuple<int> ct1; + + const int&& ct1one __attribute__((unused)) = std::get<0>(std::move(ct1)); + + const std::tuple<float, int> ct2; + + const float&& ct2one __attribute__((unused)) = std::get<0>(std::move(ct2)); + const int&& ct2two __attribute__((unused)) = std::get<1>(std::move(ct2)); + + const std::tuple<short, int, double> ct3; + + const short&& ct3one __attribute__((unused)) = std::get<0>(std::move(ct3)); + const int&& ct3two __attribute__((unused)) = std::get<1>(std::move(ct3)); + const double&& ct3thr __attribute__((unused)) = std::get<2>(std::move(ct3)); } diff --git a/libstdc++-v3/testsuite/20_util/tuple/element_access/get2_by_type.cc b/libstdc++-v3/testsuite/20_util/tuple/element_access/get2_by_type.cc index 337934d57e2..cdc1030059a 100644 --- a/libstdc++-v3/testsuite/20_util/tuple/element_access/get2_by_type.cc +++ b/libstdc++-v3/testsuite/20_util/tuple/element_access/get2_by_type.cc @@ -35,4 +35,22 @@ void test01() short&& t3one __attribute__((unused)) = std::get<short>(std::move(t3)); int&& t3two __attribute__((unused)) = std::get<int>(std::move(t3)); double&& t3thr __attribute__((unused)) = std::get<double>(std::move(t3)); + + const std::tuple<int> ct1; + + const int&& ct1one __attribute__((unused)) = std::get<int>(std::move(ct1)); + + const std::tuple<float, int> ct2; + + const float&& ct2one __attribute__((unused)) = std::get<0>(std::move(ct2)); + const int&& ct2two __attribute__((unused)) = std::get<int>(std::move(ct2)); + + const std::tuple<short, int, double> ct3; + + const short&& ct3one __attribute__((unused)) = + std::get<short>(std::move(ct3)); + const int&& ct3two __attribute__((unused)) = + std::get<int>(std::move(ct3)); + const double&& ct3thr __attribute__((unused)) = + std::get<double>(std::move(ct3)); } diff --git a/libstdc++-v3/testsuite/21_strings/headers/string/synopsis.cc b/libstdc++-v3/testsuite/21_strings/headers/string/synopsis.cc index d27d22076a1..568d846cba7 100644 --- a/libstdc++-v3/testsuite/21_strings/headers/string/synopsis.cc +++ b/libstdc++-v3/testsuite/21_strings/headers/string/synopsis.cc @@ -1,4 +1,5 @@ // { dg-do compile } +// { dg-require-normal-namespace "" } // Copyright (C) 2007-2017 Free Software Foundation, Inc. // diff --git a/libstdc++-v3/testsuite/22_locale/headers/locale/synopsis.cc b/libstdc++-v3/testsuite/22_locale/headers/locale/synopsis.cc index 7204fd42a59..236d2e39348 100644 --- a/libstdc++-v3/testsuite/22_locale/headers/locale/synopsis.cc +++ b/libstdc++-v3/testsuite/22_locale/headers/locale/synopsis.cc @@ -1,4 +1,5 @@ // { dg-do compile } +// { dg-require-normal-namespace "" } // Copyright (C) 2007-2017 Free Software Foundation, Inc. // diff --git a/libstdc++-v3/testsuite/23_containers/array/tuple_interface/get.cc b/libstdc++-v3/testsuite/23_containers/array/tuple_interface/get.cc index a8c403c6cc7..8bc0afb0e9c 100644 --- a/libstdc++-v3/testsuite/23_containers/array/tuple_interface/get.cc +++ b/libstdc++-v3/testsuite/23_containers/array/tuple_interface/get.cc @@ -27,4 +27,9 @@ void test01() int&& aone __attribute__((unused)) = std::get<0>(std::move(a)); int&& atwo __attribute__((unused)) = std::get<1>(std::move(a)); + + const std::array<int, 2> ca{}; + + const int&& caone __attribute__((unused)) = std::get<0>(std::move(ca)); + const int&& catwo __attribute__((unused)) = std::get<1>(std::move(ca)); } diff --git a/libstdc++-v3/testsuite/23_containers/array/tuple_interface/tuple_element_debug_neg.cc b/libstdc++-v3/testsuite/23_containers/array/tuple_interface/tuple_element_debug_neg.cc index e433c6e0a63..8e8ef0d756e 100644 --- a/libstdc++-v3/testsuite/23_containers/array/tuple_interface/tuple_element_debug_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/array/tuple_interface/tuple_element_debug_neg.cc @@ -22,4 +22,4 @@ typedef std::tuple_element<1, std::array<int, 1>>::type type; -// { dg-error "static assertion failed" "" { target *-*-* } 323 } +// { dg-error "static assertion failed" "" { target *-*-* } 331 } diff --git a/libstdc++-v3/testsuite/23_containers/array/tuple_interface/tuple_element_neg.cc b/libstdc++-v3/testsuite/23_containers/array/tuple_interface/tuple_element_neg.cc index 493449a235b..4e8eb3291cb 100644 --- a/libstdc++-v3/testsuite/23_containers/array/tuple_interface/tuple_element_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/array/tuple_interface/tuple_element_neg.cc @@ -22,4 +22,4 @@ typedef std::tuple_element<1, std::array<int, 1>>::type type; -// { dg-error "static assertion failed" "" { target *-*-* } 357 } +// { dg-error "static assertion failed" "" { target *-*-* } 365 } diff --git a/libstdc++-v3/testsuite/23_containers/headers/bitset/synopsis.cc b/libstdc++-v3/testsuite/23_containers/headers/bitset/synopsis.cc index 6ef085a5dc8..8f07ce22bbb 100644 --- a/libstdc++-v3/testsuite/23_containers/headers/bitset/synopsis.cc +++ b/libstdc++-v3/testsuite/23_containers/headers/bitset/synopsis.cc @@ -1,5 +1,6 @@ // { dg-do compile } // { dg-require-normal-mode "" } +// { dg-require-normal-namespace "" } // Copyright (C) 2007-2017 Free Software Foundation, Inc. // diff --git a/libstdc++-v3/testsuite/23_containers/headers/deque/synopsis.cc b/libstdc++-v3/testsuite/23_containers/headers/deque/synopsis.cc index aa2b7871145..76f10a5f5f9 100644 --- a/libstdc++-v3/testsuite/23_containers/headers/deque/synopsis.cc +++ b/libstdc++-v3/testsuite/23_containers/headers/deque/synopsis.cc @@ -1,5 +1,6 @@ // { dg-do compile } // { dg-require-normal-mode "" } +// { dg-require-normal-namespace "" } // Copyright (C) 2007-2017 Free Software Foundation, Inc. // diff --git a/libstdc++-v3/testsuite/23_containers/headers/forward_list/synopsis.cc b/libstdc++-v3/testsuite/23_containers/headers/forward_list/synopsis.cc index b1792ceb4d9..c9f1df572af 100644 --- a/libstdc++-v3/testsuite/23_containers/headers/forward_list/synopsis.cc +++ b/libstdc++-v3/testsuite/23_containers/headers/forward_list/synopsis.cc @@ -1,5 +1,6 @@ // { dg-do compile { target c++11 } } // { dg-require-normal-mode "" } +// { dg-require-normal-namespace "" } // Copyright (C) 2008-2017 Free Software Foundation, Inc. // diff --git a/libstdc++-v3/testsuite/23_containers/headers/list/synopsis.cc b/libstdc++-v3/testsuite/23_containers/headers/list/synopsis.cc index ab22b9fce7e..bcc03764b05 100644 --- a/libstdc++-v3/testsuite/23_containers/headers/list/synopsis.cc +++ b/libstdc++-v3/testsuite/23_containers/headers/list/synopsis.cc @@ -1,5 +1,6 @@ // { dg-do compile } // { dg-require-normal-mode "" } +// { dg-require-normal-namespace "" } // Copyright (C) 2007-2017 Free Software Foundation, Inc. // diff --git a/libstdc++-v3/testsuite/23_containers/headers/map/synopsis.cc b/libstdc++-v3/testsuite/23_containers/headers/map/synopsis.cc index f4a08265293..8d43335cbb1 100644 --- a/libstdc++-v3/testsuite/23_containers/headers/map/synopsis.cc +++ b/libstdc++-v3/testsuite/23_containers/headers/map/synopsis.cc @@ -1,5 +1,6 @@ // { dg-do compile } // { dg-require-normal-mode "" } +// { dg-require-normal-namespace "" } // Copyright (C) 2007-2017 Free Software Foundation, Inc. // diff --git a/libstdc++-v3/testsuite/23_containers/headers/queue/synopsis.cc b/libstdc++-v3/testsuite/23_containers/headers/queue/synopsis.cc index f03d5778161..8c549b3c4f5 100644 --- a/libstdc++-v3/testsuite/23_containers/headers/queue/synopsis.cc +++ b/libstdc++-v3/testsuite/23_containers/headers/queue/synopsis.cc @@ -1,4 +1,5 @@ // { dg-do compile } +// { dg-require-normal-namespace "" } // Copyright (C) 2007-2017 Free Software Foundation, Inc. // diff --git a/libstdc++-v3/testsuite/23_containers/headers/set/synopsis.cc b/libstdc++-v3/testsuite/23_containers/headers/set/synopsis.cc index e50a044977c..9a8df57b411 100644 --- a/libstdc++-v3/testsuite/23_containers/headers/set/synopsis.cc +++ b/libstdc++-v3/testsuite/23_containers/headers/set/synopsis.cc @@ -1,5 +1,6 @@ // { dg-do compile } // { dg-require-normal-mode "" } +// { dg-require-normal-namespace "" } // Copyright (C) 2007-2017 Free Software Foundation, Inc. // diff --git a/libstdc++-v3/testsuite/23_containers/headers/stack/synopsis.cc b/libstdc++-v3/testsuite/23_containers/headers/stack/synopsis.cc index f1bac94f0f2..aff07dcea0d 100644 --- a/libstdc++-v3/testsuite/23_containers/headers/stack/synopsis.cc +++ b/libstdc++-v3/testsuite/23_containers/headers/stack/synopsis.cc @@ -1,4 +1,5 @@ // { dg-do compile } +// { dg-require-normal-namespace "" } // Copyright (C) 2007-2017 Free Software Foundation, Inc. // diff --git a/libstdc++-v3/testsuite/23_containers/headers/vector/synopsis.cc b/libstdc++-v3/testsuite/23_containers/headers/vector/synopsis.cc index c127b5dee17..12a7197032a 100644 --- a/libstdc++-v3/testsuite/23_containers/headers/vector/synopsis.cc +++ b/libstdc++-v3/testsuite/23_containers/headers/vector/synopsis.cc @@ -1,5 +1,6 @@ // { dg-do compile } // { dg-require-normal-mode "" } +// { dg-require-normal-namespace "" } // Copyright (C) 2007-2017 Free Software Foundation, Inc. // diff --git a/libstdc++-v3/testsuite/23_containers/map/cons/deduction.cc b/libstdc++-v3/testsuite/23_containers/map/cons/deduction.cc new file mode 100644 index 00000000000..3880cd5e79d --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/cons/deduction.cc @@ -0,0 +1,68 @@ +// { dg-options "-std=gnu++17" } +// { dg-do compile { target c++17 } } + +#include <map> +#include <testsuite_allocator.h> + +using __gnu_test::SimpleAllocator; + +static_assert(std::is_same_v< + decltype(std::map{std::pair{1, 2.0}, {2, 3.0}, {3, 4.0}}), + std::map<int, double>>); + +static_assert(std::is_same_v< + decltype(std::map{{std::pair{1, 2.0}, {2, 3.0}, {3, 4.0}}}), + std::map<int, double>>); + +static_assert(std::is_same_v< + decltype(std::map{{std::pair{1, 2.0}, {2, 3.0}, {3, 4.0}}, + std::less<int>{}, {}}), + std::map<int, double>>); + +static_assert(std::is_same_v< + decltype(std::map{{std::pair{1, 2.0}, {2, 3.0}, {3, 4.0}}, + {}}), + std::map<int, double>>); + +static_assert(std::is_same_v< + decltype(std::map{{std::pair{1, 2.0}, {2, 3.0}, {3, 4.0}}, + {}, SimpleAllocator<std::pair<const int, double>>{}}), + std::map<int, double, std::less<int>, + SimpleAllocator<std::pair<const int, double>>>>); + +void f() +{ + std::map<int, double> x; + static_assert(std::is_same_v< + decltype(std::map(x.begin(), x.end())), + std::map<int, double>>); + + static_assert(std::is_same_v< + decltype(std::map{x.begin(), x.end(), + std::less<int>{}, + std::allocator<std::pair<const int, double>>{}}), + std::map<int, double>>); + + static_assert(std::is_same_v< + decltype(std::map{x.begin(), x.end(), + std::less<int>{}, {}}), + std::map<int, double>>); + + static_assert(std::is_same_v< + decltype(std::map(x.begin(), x.end(), + {})), + std::map<int, double>>); + + static_assert(std::is_same_v< + decltype(std::map{x.begin(), x.end(), + {}, + std::allocator<std::pair<const int, double>>{}}), + std::map<int, double>>); + + static_assert(std::is_same_v< + decltype(std::map{x.begin(), x.end(), + {}, + SimpleAllocator<std::pair<const int, double>>{}}), + std::map<int, double, std::less<int>, + SimpleAllocator<std::pair<const int, double>>>>); +} diff --git a/libstdc++-v3/testsuite/23_containers/map/modifiers/erase/abi_tag.cc b/libstdc++-v3/testsuite/23_containers/map/modifiers/erase/abi_tag.cc index 65e85893781..7b5beee5238 100644 --- a/libstdc++-v3/testsuite/23_containers/map/modifiers/erase/abi_tag.cc +++ b/libstdc++-v3/testsuite/23_containers/map/modifiers/erase/abi_tag.cc @@ -1,5 +1,6 @@ // { dg-do compile { target c++11 } } // { dg-require-normal-mode "" } +// { dg-require-normal-namespace "" } // Copyright (C) 2013-2017 Free Software Foundation, Inc. // diff --git a/libstdc++-v3/testsuite/23_containers/map/modifiers/insert/dr2354.cc b/libstdc++-v3/testsuite/23_containers/map/modifiers/insert/dr2354.cc new file mode 100644 index 00000000000..338d9fd3f1e --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/modifiers/insert/dr2354.cc @@ -0,0 +1,32 @@ +// Copyright (C) 2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-do compile { target c++11 } } + +#include <map> + +struct MoveOnly { + MoveOnly(int) { } + MoveOnly(MoveOnly&&) = default; +}; + +void +test01() +{ + std::map<int, MoveOnly> m; + m.insert({1, 2}); // PR libstdc++/82522 - LWG 2354 +} diff --git a/libstdc++-v3/testsuite/23_containers/multimap/cons/deduction.cc b/libstdc++-v3/testsuite/23_containers/multimap/cons/deduction.cc new file mode 100644 index 00000000000..ee48bfda26b --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/cons/deduction.cc @@ -0,0 +1,68 @@ +// { dg-options "-std=gnu++17" } +// { dg-do compile { target c++17 } } + +#include <map> +#include <testsuite_allocator.h> + +using __gnu_test::SimpleAllocator; + +static_assert(std::is_same_v< + decltype(std::multimap{std::pair{1, 2.0}, {2, 3.0}, {3, 4.0}}), + std::multimap<int, double>>); + +static_assert(std::is_same_v< + decltype(std::multimap{{std::pair{1, 2.0}, {2, 3.0}, {3, 4.0}}}), + std::multimap<int, double>>); + +static_assert(std::is_same_v< + decltype(std::multimap{{std::pair{1, 2.0}, {2, 3.0}, {3, 4.0}}, + std::less<int>{}, {}}), + std::multimap<int, double>>); + +static_assert(std::is_same_v< + decltype(std::multimap{{std::pair{1, 2.0}, {2, 3.0}, {3, 4.0}}, + {}}), + std::multimap<int, double>>); + +static_assert(std::is_same_v< + decltype(std::multimap{{std::pair{1, 2.0}, {2, 3.0}, {3, 4.0}}, + {}, SimpleAllocator<std::pair<const int, double>>{}}), + std::multimap<int, double, std::less<int>, + SimpleAllocator<std::pair<const int, double>>>>); + +void f() +{ + std::multimap<int, double> x; + static_assert(std::is_same_v< + decltype(std::multimap(x.begin(), x.end())), + std::multimap<int, double>>); + + static_assert(std::is_same_v< + decltype(std::multimap{x.begin(), x.end(), + std::less<int>{}, + std::allocator<std::pair<const int, double>>{}}), + std::multimap<int, double>>); + + static_assert(std::is_same_v< + decltype(std::multimap{x.begin(), x.end(), + std::less<int>{}, {}}), + std::multimap<int, double>>); + + static_assert(std::is_same_v< + decltype(std::multimap(x.begin(), x.end(), + {})), + std::multimap<int, double>>); + + static_assert(std::is_same_v< + decltype(std::multimap{x.begin(), x.end(), + {}, + std::allocator<std::pair<const int, double>>{}}), + std::multimap<int, double>>); + + static_assert(std::is_same_v< + decltype(std::multimap{x.begin(), x.end(), + {}, + SimpleAllocator<std::pair<const int, double>>{}}), + std::multimap<int, double, std::less<int>, + SimpleAllocator<std::pair<const int, double>>>>); +} diff --git a/libstdc++-v3/testsuite/23_containers/multimap/modifiers/erase/abi_tag.cc b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/erase/abi_tag.cc index a25dba74edb..10d1efef3e8 100644 --- a/libstdc++-v3/testsuite/23_containers/multimap/modifiers/erase/abi_tag.cc +++ b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/erase/abi_tag.cc @@ -1,5 +1,6 @@ // { dg-do compile { target c++11 } } // { dg-require-normal-mode "" } +// { dg-require-normal-namespace "" } // Copyright (C) 2013-2017 Free Software Foundation, Inc. // diff --git a/libstdc++-v3/testsuite/23_containers/multimap/modifiers/insert/dr2354.cc b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/insert/dr2354.cc new file mode 100644 index 00000000000..ca743ec4ce9 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/insert/dr2354.cc @@ -0,0 +1,32 @@ +// Copyright (C) 2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-do compile { target c++11 } } + +#include <map> + +struct MoveOnly { + MoveOnly(int) { } + MoveOnly(MoveOnly&&) = default; +}; + +void +test01() +{ + std::multimap<int, MoveOnly> m; + m.insert({1, 2}); // PR libstdc++/82522 - LWG 2354 +} diff --git a/libstdc++-v3/testsuite/23_containers/multiset/cons/deduction.cc b/libstdc++-v3/testsuite/23_containers/multiset/cons/deduction.cc new file mode 100644 index 00000000000..4ca3f98129a --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multiset/cons/deduction.cc @@ -0,0 +1,68 @@ +// { dg-options "-std=gnu++17" } +// { dg-do compile { target c++17 } } + +#include <set> +#include <testsuite_allocator.h> + +using __gnu_test::SimpleAllocator; + +static_assert(std::is_same_v< + decltype(std::multiset{1, 2, 3}), + std::multiset<int>>); + +static_assert(std::is_same_v< + decltype(std::multiset{1, 2, 3}), + std::multiset<int>>); + +static_assert(std::is_same_v< + decltype(std::multiset{{1, 2, 3}, + std::less<int>{}, {}}), + std::multiset<int>>); + +static_assert(std::is_same_v< + decltype(std::multiset{{1, 2, 3}, + {}}), + std::multiset<int>>); + +static_assert(std::is_same_v< + decltype(std::multiset{{1, 2, 3}, + {}, SimpleAllocator<int>{}}), + std::multiset<int, std::less<int>, + SimpleAllocator<int>>>); + +void f() +{ + std::multiset<int> x; + + static_assert(std::is_same_v< + decltype(std::multiset(x.begin(), x.end())), + std::multiset<int>>); + + static_assert(std::is_same_v< + decltype(std::multiset{x.begin(), x.end(), + std::less<int>{}, + std::allocator<int>{}}), + std::multiset<int>>); + + static_assert(std::is_same_v< + decltype(std::multiset{x.begin(), x.end(), + std::less<int>{}, {}}), + std::multiset<int>>); + + static_assert(std::is_same_v< + decltype(std::multiset(x.begin(), x.end(), + {})), + std::multiset<int>>); + + static_assert(std::is_same_v< + decltype(std::multiset{x.begin(), x.end(), + {}, + std::allocator<int>{}}), + std::multiset<int>>); + + static_assert(std::is_same_v< + decltype(std::multiset{x.begin(), x.end(), + {}, + SimpleAllocator<int>{}}), + std::multiset<int, std::less<int>, SimpleAllocator<int>>>); +} diff --git a/libstdc++-v3/testsuite/23_containers/multiset/modifiers/erase/abi_tag.cc b/libstdc++-v3/testsuite/23_containers/multiset/modifiers/erase/abi_tag.cc index fafe4b6609c..0ea0c7ea229 100644 --- a/libstdc++-v3/testsuite/23_containers/multiset/modifiers/erase/abi_tag.cc +++ b/libstdc++-v3/testsuite/23_containers/multiset/modifiers/erase/abi_tag.cc @@ -1,5 +1,6 @@ // { dg-do compile { target c++11 } } // { dg-require-normal-mode "" } +// { dg-require-normal-namespace "" } // Copyright (C) 2013-2017 Free Software Foundation, Inc. // diff --git a/libstdc++-v3/testsuite/23_containers/set/cons/deduction.cc b/libstdc++-v3/testsuite/23_containers/set/cons/deduction.cc new file mode 100644 index 00000000000..73d5cfdd227 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/set/cons/deduction.cc @@ -0,0 +1,68 @@ +// { dg-options "-std=gnu++17" } +// { dg-do compile { target c++17 } } + +#include <set> +#include <testsuite_allocator.h> + +using __gnu_test::SimpleAllocator; + +static_assert(std::is_same_v< + decltype(std::set{1, 2, 3}), + std::set<int>>); + +static_assert(std::is_same_v< + decltype(std::set{1, 2, 3}), + std::set<int>>); + +static_assert(std::is_same_v< + decltype(std::set{{1, 2, 3}, + std::less<int>{}, {}}), + std::set<int>>); + +static_assert(std::is_same_v< + decltype(std::set{{1, 2, 3}, + {}}), + std::set<int>>); + +static_assert(std::is_same_v< + decltype(std::set{{1, 2, 3}, + {}, SimpleAllocator<int>{}}), + std::set<int, std::less<int>, + SimpleAllocator<int>>>); + +void f() +{ + std::set<int> x; + + static_assert(std::is_same_v< + decltype(std::set(x.begin(), x.end())), + std::set<int>>); + + static_assert(std::is_same_v< + decltype(std::set{x.begin(), x.end(), + std::less<int>{}, + std::allocator<int>{}}), + std::set<int>>); + + static_assert(std::is_same_v< + decltype(std::set{x.begin(), x.end(), + std::less<int>{}, {}}), + std::set<int>>); + + static_assert(std::is_same_v< + decltype(std::set(x.begin(), x.end(), + {})), + std::set<int>>); + + static_assert(std::is_same_v< + decltype(std::set{x.begin(), x.end(), + {}, + std::allocator<int>{}}), + std::set<int>>); + + static_assert(std::is_same_v< + decltype(std::set{x.begin(), x.end(), + {}, + SimpleAllocator<int>{}}), + std::set<int, std::less<int>, SimpleAllocator<int>>>); +} diff --git a/libstdc++-v3/testsuite/23_containers/set/modifiers/erase/abi_tag.cc b/libstdc++-v3/testsuite/23_containers/set/modifiers/erase/abi_tag.cc index 9734e6ab437..f89797a4780 100644 --- a/libstdc++-v3/testsuite/23_containers/set/modifiers/erase/abi_tag.cc +++ b/libstdc++-v3/testsuite/23_containers/set/modifiers/erase/abi_tag.cc @@ -1,5 +1,6 @@ // { dg-do compile { target c++11 } } // { dg-require-normal-mode "" } +// { dg-require-normal-namespace "" } // Copyright (C) 2013-2017 Free Software Foundation, Inc. // diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/cons/deduction.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/cons/deduction.cc new file mode 100644 index 00000000000..1905b20116b --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_map/cons/deduction.cc @@ -0,0 +1,77 @@ +// { dg-options "-std=gnu++17" } +// { dg-do compile { target c++17 } } + +#include <unordered_map> +#include <testsuite_allocator.h> + +using __gnu_test::SimpleAllocator; + +static_assert(std::is_same_v< + decltype(std::unordered_map{std::pair{1, 2.0}, + {2, 3.0}, {3, 4.0}}), + std::unordered_map<int, double>>); + +static_assert(std::is_same_v< + decltype(std::unordered_map{{std::pair{1, 2.0}, + {2, 3.0}, {3, 4.0}}}), + std::unordered_map<int, double>>); + +static_assert(std::is_same_v< + decltype(std::unordered_map{{std::pair{1, 2.0}, + {2, 3.0}, {3, 4.0}}, + {}, std::hash<int>{}, {}}), + std::unordered_map<int, double>>); + +static_assert(std::is_same_v< + decltype(std::unordered_map{{std::pair{1, 2.0}, + {2, 3.0}, {3, 4.0}}, + {}}), + std::unordered_map<int, double>>); + +static_assert(std::is_same_v< + decltype(std::unordered_map{{std::pair{1, 2.0}, + {2, 3.0}, {3, 4.0}}, + {}, {}, {}, + SimpleAllocator<std::pair<const int, double>>{}}), + std::unordered_map<int, double, std::hash<int>, + std::equal_to<int>, + SimpleAllocator<std::pair<const int, double>>>>); + + +void f() +{ + std::unordered_map<int, double> x; + static_assert(std::is_same_v< + decltype(std::unordered_map(x.begin(), x.end())), + std::unordered_map<int, double>>); + + static_assert(std::is_same_v< + decltype(std::unordered_map{x.begin(), x.end(), + {}, std::hash<int>{}, {}, + std::allocator<std::pair<const int, double>>{}}), + std::unordered_map<int, double>>); + + static_assert(std::is_same_v< + decltype(std::unordered_map{x.begin(), x.end(), + {}, std::hash<int>{}, {}}), + std::unordered_map<int, double>>); + + static_assert(std::is_same_v< + decltype(std::unordered_map(x.begin(), x.end(), + {})), + std::unordered_map<int, double>>); + + static_assert(std::is_same_v< + decltype(std::unordered_map{x.begin(), x.end(), + {}, {}, {}, + std::allocator<std::pair<const int, double>>{}}), + std::unordered_map<int, double>>); + + static_assert(std::is_same_v< + decltype(std::unordered_map{x.begin(), x.end(), + {}, {}, {}, + SimpleAllocator<std::pair<const int, double>>{}}), + std::unordered_map<int, double, std::hash<int>, + std::equal_to<int>, + SimpleAllocator<std::pair<const int, double>>>>); +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/insert/dr2354.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/insert/dr2354.cc new file mode 100644 index 00000000000..fe5356594c3 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_map/insert/dr2354.cc @@ -0,0 +1,32 @@ +// Copyright (C) 2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-do compile { target c++11 } } + +#include <unordered_map> + +struct MoveOnly { + MoveOnly(int) { } + MoveOnly(MoveOnly&&) = default; +}; + +void +test01() +{ + std::unordered_map<int, MoveOnly> m; + m.insert({1, 2}); // PR libstdc++/82522 - LWG 2354 +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multimap/cons/deduction.cc b/libstdc++-v3/testsuite/23_containers/unordered_multimap/cons/deduction.cc new file mode 100644 index 00000000000..db5e32b4ad2 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multimap/cons/deduction.cc @@ -0,0 +1,77 @@ +// { dg-options "-std=gnu++17" } +// { dg-do compile { target c++17 } } + +#include <unordered_map> +#include <testsuite_allocator.h> + +using __gnu_test::SimpleAllocator; + +static_assert(std::is_same_v< + decltype(std::unordered_multimap{std::pair{1, 2.0}, + {2, 3.0}, {3, 4.0}}), + std::unordered_multimap<int, double>>); + +static_assert(std::is_same_v< + decltype(std::unordered_multimap{{std::pair{1, 2.0}, + {2, 3.0}, {3, 4.0}}}), + std::unordered_multimap<int, double>>); + +static_assert(std::is_same_v< + decltype(std::unordered_multimap{{std::pair{1, 2.0}, + {2, 3.0}, {3, 4.0}}, + {}, std::hash<int>{}, {}}), + std::unordered_multimap<int, double>>); + +static_assert(std::is_same_v< + decltype(std::unordered_multimap{{std::pair{1, 2.0}, + {2, 3.0}, {3, 4.0}}, + {}}), + std::unordered_multimap<int, double>>); + +static_assert(std::is_same_v< + decltype(std::unordered_multimap{{std::pair{1, 2.0}, + {2, 3.0}, {3, 4.0}}, + {}, {}, {}, + SimpleAllocator<std::pair<const int, double>>{}}), + std::unordered_multimap<int, double, std::hash<int>, + std::equal_to<int>, + SimpleAllocator<std::pair<const int, double>>>>); + + +void f() +{ + std::unordered_multimap<int, double> x; + static_assert(std::is_same_v< + decltype(std::unordered_multimap(x.begin(), x.end())), + std::unordered_multimap<int, double>>); + + static_assert(std::is_same_v< + decltype(std::unordered_multimap{x.begin(), x.end(), + {}, std::hash<int>{}, {}, + std::allocator<std::pair<const int, double>>{}}), + std::unordered_multimap<int, double>>); + + static_assert(std::is_same_v< + decltype(std::unordered_multimap{x.begin(), x.end(), + {}, std::hash<int>{}, {}}), + std::unordered_multimap<int, double>>); + + static_assert(std::is_same_v< + decltype(std::unordered_multimap(x.begin(), x.end(), + {})), + std::unordered_multimap<int, double>>); + + static_assert(std::is_same_v< + decltype(std::unordered_multimap{x.begin(), x.end(), + {}, {}, {}, + std::allocator<std::pair<const int, double>>{}}), + std::unordered_multimap<int, double>>); + + static_assert(std::is_same_v< + decltype(std::unordered_multimap{x.begin(), x.end(), + {}, {}, {}, + SimpleAllocator<std::pair<const int, double>>{}}), + std::unordered_multimap<int, double, std::hash<int>, + std::equal_to<int>, + SimpleAllocator<std::pair<const int, double>>>>); +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multimap/insert/dr2354.cc b/libstdc++-v3/testsuite/23_containers/unordered_multimap/insert/dr2354.cc new file mode 100644 index 00000000000..5a27242c4e0 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multimap/insert/dr2354.cc @@ -0,0 +1,32 @@ +// Copyright (C) 2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-do compile { target c++11 } } + +#include <unordered_map> + +struct MoveOnly { + MoveOnly(int) { } + MoveOnly(MoveOnly&&) = default; +}; + +void +test01() +{ + std::unordered_multimap<int, MoveOnly> m; + m.insert({1, 2}); // PR libstdc++/82522 - LWG 2354 +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multiset/cons/deduction.cc b/libstdc++-v3/testsuite/23_containers/unordered_multiset/cons/deduction.cc new file mode 100644 index 00000000000..352176d1e7d --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multiset/cons/deduction.cc @@ -0,0 +1,78 @@ +// { dg-options "-std=gnu++17" } +// { dg-do compile { target c++17 } } + +#include <unordered_set> +#include <testsuite_allocator.h> + +using __gnu_test::SimpleAllocator; + +static_assert(std::is_same_v< + decltype(std::unordered_multiset{1, 2, 3}), + std::unordered_multiset<int>>); + +static_assert(std::is_same_v< + decltype(std::unordered_multiset{1, 2, 3}), + std::unordered_multiset<int>>); + +static_assert(std::is_same_v< + decltype(std::unordered_multiset{{1, 2, 3}, + 0, std::hash<int>{}, {}}), + std::unordered_multiset<int>>); + +static_assert(std::is_same_v< + decltype(std::unordered_multiset{{1, 2, 3}, + {}}), + std::unordered_multiset<int>>); + +static_assert(std::is_same_v< + decltype(std::unordered_multiset{{1, 2, 3}, + {}, {}, {}, std::allocator<int>{}}), + std::unordered_multiset<int>>); + +static_assert(std::is_same_v< + decltype(std::unordered_multiset{{1, 2, 3}, + {}, {}, {}, SimpleAllocator<int>{}}), + std::unordered_multiset<int, std::hash<int>, + std::equal_to<int>, + SimpleAllocator<int>>>); + +void f() +{ + std::unordered_multiset<int> x; + + static_assert(std::is_same_v< + decltype(std::unordered_multiset(x.begin(), x.end())), + std::unordered_multiset<int>>); + + static_assert(std::is_same_v< + decltype(std::unordered_multiset{x.begin(), x.end(), + {}, + std::hash<int>{}, + std::equal_to<int>{}, + std::allocator<int>{}}), + std::unordered_multiset<int>>); + + static_assert(std::is_same_v< + decltype(std::unordered_multiset{x.begin(), x.end(), + {}, std::hash<int>{}, {}}), + std::unordered_multiset<int>>); + + static_assert(std::is_same_v< + decltype(std::unordered_multiset(x.begin(), x.end(), + {})), + std::unordered_multiset<int>>); + + static_assert(std::is_same_v< + decltype(std::unordered_multiset{x.begin(), x.end(), + {}, {}, {}, + std::allocator<int>{}}), + std::unordered_multiset<int>>); + + static_assert(std::is_same_v< + decltype(std::unordered_multiset{x.begin(), x.end(), + {}, {}, {}, + SimpleAllocator<int>{}}), + std::unordered_multiset<int, std::hash<int>, + std::equal_to<int>, + SimpleAllocator<int>>>); +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/cons/deduction.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/cons/deduction.cc new file mode 100644 index 00000000000..c7e1798ef7d --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_set/cons/deduction.cc @@ -0,0 +1,78 @@ +// { dg-options "-std=gnu++17" } +// { dg-do compile { target c++17 } } + +#include <unordered_set> +#include <testsuite_allocator.h> + +using __gnu_test::SimpleAllocator; + +static_assert(std::is_same_v< + decltype(std::unordered_set{1, 2, 3}), + std::unordered_set<int>>); + +static_assert(std::is_same_v< + decltype(std::unordered_set{1, 2, 3}), + std::unordered_set<int>>); + +static_assert(std::is_same_v< + decltype(std::unordered_set{{1, 2, 3}, + 0, std::hash<int>{}, {}}), + std::unordered_set<int>>); + +static_assert(std::is_same_v< + decltype(std::unordered_set{{1, 2, 3}, + {}}), + std::unordered_set<int>>); + +static_assert(std::is_same_v< + decltype(std::unordered_set{{1, 2, 3}, + {}, {}, {}, std::allocator<int>{}}), + std::unordered_set<int>>); + +static_assert(std::is_same_v< + decltype(std::unordered_set{{1, 2, 3}, + {}, {}, {}, SimpleAllocator<int>{}}), + std::unordered_set<int, std::hash<int>, + std::equal_to<int>, + SimpleAllocator<int>>>); + +void f() +{ + std::unordered_set<int> x; + + static_assert(std::is_same_v< + decltype(std::unordered_set(x.begin(), x.end())), + std::unordered_set<int>>); + + static_assert(std::is_same_v< + decltype(std::unordered_set{x.begin(), x.end(), + {}, + std::hash<int>{}, + std::equal_to<int>{}, + std::allocator<int>{}}), + std::unordered_set<int>>); + + static_assert(std::is_same_v< + decltype(std::unordered_set{x.begin(), x.end(), + {}, std::hash<int>{}, {}}), + std::unordered_set<int>>); + + static_assert(std::is_same_v< + decltype(std::unordered_set(x.begin(), x.end(), + {})), + std::unordered_set<int>>); + + static_assert(std::is_same_v< + decltype(std::unordered_set{x.begin(), x.end(), + {}, {}, {}, + std::allocator<int>{}}), + std::unordered_set<int>>); + + static_assert(std::is_same_v< + decltype(std::unordered_set{x.begin(), x.end(), + {}, {}, {}, + SimpleAllocator<int>{}}), + std::unordered_set<int, std::hash<int>, + std::equal_to<int>, + SimpleAllocator<int>>>); +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/bool/82558.cc b/libstdc++-v3/testsuite/23_containers/vector/bool/82558.cc new file mode 100644 index 00000000000..6362688efb5 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/bool/82558.cc @@ -0,0 +1,32 @@ +// Copyright (C) 2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 23.3.8 class vector<bool> + +#include <vector> + +// libstdc++/82558 +void test01() +{ + std::vector<bool> v; + std::fill(v.begin(), v.begin(), false); +} + +int main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/24_iterators/headers/iterator/synopsis.cc b/libstdc++-v3/testsuite/24_iterators/headers/iterator/synopsis.cc index 64659c59e4f..58b731a77d3 100644 --- a/libstdc++-v3/testsuite/24_iterators/headers/iterator/synopsis.cc +++ b/libstdc++-v3/testsuite/24_iterators/headers/iterator/synopsis.cc @@ -1,5 +1,6 @@ // { dg-options "-std=gnu++98" } // { dg-do compile } +// { dg-require-normal-namespace "" } // Copyright (C) 2007-2017 Free Software Foundation, Inc. // diff --git a/libstdc++-v3/testsuite/24_iterators/headers/iterator/synopsis_c++11.cc b/libstdc++-v3/testsuite/24_iterators/headers/iterator/synopsis_c++11.cc index ae3c2652ee0..87f1488d016 100644 --- a/libstdc++-v3/testsuite/24_iterators/headers/iterator/synopsis_c++11.cc +++ b/libstdc++-v3/testsuite/24_iterators/headers/iterator/synopsis_c++11.cc @@ -1,5 +1,6 @@ // { dg-options "-std=gnu++11" } // { dg-do compile } +// { dg-require-normal-namespace "" } // Copyright (C) 2016-2017 Free Software Foundation, Inc. // diff --git a/libstdc++-v3/testsuite/24_iterators/headers/iterator/synopsis_c++14.cc b/libstdc++-v3/testsuite/24_iterators/headers/iterator/synopsis_c++14.cc index de7ae1fd38a..7370a52d44b 100644 --- a/libstdc++-v3/testsuite/24_iterators/headers/iterator/synopsis_c++14.cc +++ b/libstdc++-v3/testsuite/24_iterators/headers/iterator/synopsis_c++14.cc @@ -1,5 +1,6 @@ // { dg-options "-std=gnu++14" } // { dg-do compile } +// { dg-require-normal-namespace "" } // Copyright (C) 2016-2017 Free Software Foundation, Inc. // diff --git a/libstdc++-v3/testsuite/24_iterators/headers/iterator/synopsis_c++17.cc b/libstdc++-v3/testsuite/24_iterators/headers/iterator/synopsis_c++17.cc index 0cfab7d3bf4..8f4dd433fca 100644 --- a/libstdc++-v3/testsuite/24_iterators/headers/iterator/synopsis_c++17.cc +++ b/libstdc++-v3/testsuite/24_iterators/headers/iterator/synopsis_c++17.cc @@ -1,5 +1,6 @@ // { dg-options "-std=gnu++17" } // { dg-do compile } +// { dg-require-normal-namespace "" } // Copyright (C) 2016-2017 Free Software Foundation, Inc. // diff --git a/libstdc++-v3/testsuite/25_algorithms/fill_n/1.cc b/libstdc++-v3/testsuite/25_algorithms/fill_n/1.cc index d446e7a7b60..4d27f0bd22b 100644 --- a/libstdc++-v3/testsuite/25_algorithms/fill_n/1.cc +++ b/libstdc++-v3/testsuite/25_algorithms/fill_n/1.cc @@ -22,21 +22,36 @@ #include <algorithm> #include <vector> #include <testsuite_hooks.h> +#include <testsuite_iterators.h> + +// Non-scalar type to exercise partial specialization of fill_n implementation. +struct Value +{ + Value(int n) : n(n) { } + + operator int() const { return n; } + +private: + int n; +}; void test01() { using namespace std; + using __gnu_test::test_container; + using __gnu_test::output_iterator_wrapper; const int A1[] = {3, 3, 3, 3, 3, 3, 3, 3, 3, 3}; const int N1 = sizeof(A1) / sizeof(int); int i1[N1]; - fill_n(i1, N1, 3); + test_container<int, output_iterator_wrapper> c1(i1, i1 + N1); + fill_n(c1.begin(), N1, 3); VERIFY( equal(i1, i1 + N1, A1) ); vector<int> v1(N1); - fill_n(v1.begin(), N1, 3); + fill_n(v1.begin(), N1, Value(3)); VERIFY( equal(v1.begin(), v1.end(), A1) ); const char A2[] = {'\3', '\3', '\3', '\3', '\3', diff --git a/libstdc++-v3/testsuite/25_algorithms/generate_n/1.cc b/libstdc++-v3/testsuite/25_algorithms/generate_n/1.cc new file mode 100644 index 00000000000..dc3cb9f943b --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/generate_n/1.cc @@ -0,0 +1,47 @@ +// Copyright (C) 2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <algorithm> +#include <testsuite_hooks.h> +#include <testsuite_iterators.h> + +struct Inc +{ + int operator()() { return ++i; } + + int i; +}; + +void +test01() +{ + const int N = 3; + int array[N]; + + using __gnu_test::test_container; + using __gnu_test::output_iterator_wrapper; + test_container<int, output_iterator_wrapper> c(array, array + N); + std::generate_n(c.begin(), N, Inc()); + VERIFY(array[0] == 1); + VERIFY(array[1] == 2); + VERIFY(array[2] == 3); +} + +int main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/25_algorithms/stable_partition/1.cc b/libstdc++-v3/testsuite/25_algorithms/stable_partition/1.cc index 75851578267..f29d8170a83 100644 --- a/libstdc++-v3/testsuite/25_algorithms/stable_partition/1.cc +++ b/libstdc++-v3/testsuite/25_algorithms/stable_partition/1.cc @@ -21,6 +21,7 @@ #include <functional> #include <testsuite_new_operators.h> #include <testsuite_hooks.h> +#include <testsuite_iterators.h> const int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17}; const int B[] = {2, 4, 6, 8, 10, 12, 14, 16, 1, 3, 5, 7, 9, 11, 13, 15, 17}; @@ -41,11 +42,16 @@ void test01() { using std::stable_partition; + using __gnu_test::test_container; + using __gnu_test::forward_iterator_wrapper; int s1[N]; std::copy(A, A + N, s1); - VERIFY( stable_partition(s1, s1 + N, Pred()) == s1 + M ); + test_container<int, forward_iterator_wrapper> c(s1, s1+N); + forward_iterator_wrapper<int> expected = c.begin(); + std::advance(expected, M); + VERIFY( stable_partition(c.begin(), c.end(), Pred()) == expected); VERIFY( std::equal(s1, s1 + N, B) ); } diff --git a/libstdc++-v3/testsuite/26_numerics/complex/abi_tag.cc b/libstdc++-v3/testsuite/26_numerics/complex/abi_tag.cc index 09833add310..2f8569eb8b9 100644 --- a/libstdc++-v3/testsuite/26_numerics/complex/abi_tag.cc +++ b/libstdc++-v3/testsuite/26_numerics/complex/abi_tag.cc @@ -1,5 +1,6 @@ // Test that the C++11 variants of real/imag have an ABI tag // { dg-do compile { target c++11 } } +// { dg-require-normal-namespace "" } #include <complex> diff --git a/libstdc++-v3/testsuite/26_numerics/headers/cmath/82644.cc b/libstdc++-v3/testsuite/26_numerics/headers/cmath/82644.cc new file mode 100644 index 00000000000..956541a67d9 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/headers/cmath/82644.cc @@ -0,0 +1,27 @@ +// Copyright (C) 2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-options "-D__STDCPP_WANT_MATH_SPEC_FUNCS__ -D__STRICT_ANSI__" } +// { dg-do compile { target c++11 } } + +#define conf_hyperg 1 +#define conf_hypergf 2 +#define conf_hypergl 3 +#define hyperg 4 +#define hypergf 5 +#define hypergl 6 +#include <cmath> // PR libstdc++/82644 diff --git a/libstdc++-v3/testsuite/26_numerics/headers/cmath/functions_global_c++17.cc b/libstdc++-v3/testsuite/26_numerics/headers/cmath/functions_global_c++17.cc new file mode 100644 index 00000000000..ce3a0dd4ac2 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/headers/cmath/functions_global_c++17.cc @@ -0,0 +1,111 @@ +// Copyright (C) 2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-options "-std=gnu++17" } +// { dg-do compile } + +#include <math.h> + +namespace gnu +{ + using ::acos; + using ::asin; + using ::atan; + using ::atan2; + using ::ceil; + using ::cos; + using ::cosh; + using ::exp; + using ::fabs; + using ::floor; + using ::fmod; + using ::frexp; + using ::ldexp; + using ::log; + using ::log10; + using ::modf; + using ::pow; + using ::sin; + using ::sinh; + using ::sqrt; + using ::tan; + using ::tanh; + + using ::assoc_laguerre; + using ::assoc_laguerref; + using ::assoc_laguerrel; + using ::assoc_legendre; + using ::assoc_legendref; + using ::assoc_legendrel; + using ::beta; + using ::betaf; + using ::betal; + using ::comp_ellint_1; + using ::comp_ellint_1f; + using ::comp_ellint_1l; + using ::comp_ellint_2; + using ::comp_ellint_2f; + using ::comp_ellint_2l; + using ::comp_ellint_3; + using ::comp_ellint_3f; + using ::comp_ellint_3l; + using ::cyl_bessel_i; + using ::cyl_bessel_if; + using ::cyl_bessel_il; + using ::cyl_bessel_j; + using ::cyl_bessel_jf; + using ::cyl_bessel_jl; + using ::cyl_bessel_k; + using ::cyl_bessel_kf; + using ::cyl_bessel_kl; + using ::cyl_neumann; + using ::cyl_neumannf; + using ::cyl_neumannl; + using ::ellint_1; + using ::ellint_1f; + using ::ellint_1l; + using ::ellint_2; + using ::ellint_2f; + using ::ellint_2l; + using ::ellint_3; + using ::ellint_3f; + using ::ellint_3l; + using ::expint; + using ::expintf; + using ::expintl; + using ::hermite; + using ::hermitef; + using ::hermitel; + using ::laguerre; + using ::laguerref; + using ::laguerrel; + using ::legendre; + using ::legendref; + using ::legendrel; + using ::riemann_zeta; + using ::riemann_zetaf; + using ::riemann_zetal; + using ::sph_bessel; + using ::sph_besself; + using ::sph_bessell; + using ::sph_legendre; + using ::sph_legendref; + using ::sph_legendrel; + using ::sph_neumann; + using ::sph_neumannf; + using ::sph_neumannl; +} diff --git a/libstdc++-v3/testsuite/26_numerics/headers/complex/synopsis.cc b/libstdc++-v3/testsuite/26_numerics/headers/complex/synopsis.cc index 11531862882..7ab5e7628e5 100644 --- a/libstdc++-v3/testsuite/26_numerics/headers/complex/synopsis.cc +++ b/libstdc++-v3/testsuite/26_numerics/headers/complex/synopsis.cc @@ -1,4 +1,5 @@ // { dg-do compile } +// { dg-require-normal-namespace "" } // Copyright (C) 2007-2017 Free Software Foundation, Inc. // diff --git a/libstdc++-v3/testsuite/26_numerics/headers/valarray/synopsis.cc b/libstdc++-v3/testsuite/26_numerics/headers/valarray/synopsis.cc index 2983aa73355..886d817b2d1 100644 --- a/libstdc++-v3/testsuite/26_numerics/headers/valarray/synopsis.cc +++ b/libstdc++-v3/testsuite/26_numerics/headers/valarray/synopsis.cc @@ -1,4 +1,5 @@ // { dg-do compile } +// { dg-require-normal-namespace "" } // Copyright (C) 2007-2017 Free Software Foundation, Inc. // diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/path.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/path.cc new file mode 100644 index 00000000000..56fffde5f9b --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/path.cc @@ -0,0 +1,41 @@ +// Copyright (C) 2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-fileio "" } +// { dg-require-filesystem-ts "" } + +#include <fstream> +#include <filesystem> +#include <testsuite_hooks.h> + +const std::filesystem::path filename = "filebuf_members-1.tst"; + +void +test01() +{ + std::filebuf fb; + fb.open(filename, std::ios::in); + VERIFY( fb.is_open() ); +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_fstream/cons/char/path.cc b/libstdc++-v3/testsuite/27_io/basic_fstream/cons/char/path.cc new file mode 100644 index 00000000000..4442c28c56b --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_fstream/cons/char/path.cc @@ -0,0 +1,48 @@ +// Copyright (C) 2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-fileio "" } +// { dg-require-filesystem-ts "" } + +#include <fstream> +#include <filesystem> +#include <testsuite_hooks.h> + +const std::filesystem::path filename = "ofstream_members-1.tst"; + +void +test01() +{ + std::fstream f(filename); + VERIFY( f.is_open() ); +} + +void +test02() +{ + std::fstream f(filename, std::ios::out); + VERIFY( f.is_open() ); +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_fstream/open/char/path.cc b/libstdc++-v3/testsuite/27_io/basic_fstream/open/char/path.cc new file mode 100644 index 00000000000..8d0127be2b8 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_fstream/open/char/path.cc @@ -0,0 +1,50 @@ +// Copyright (C) 2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-fileio "" } +// { dg-require-filesystem-ts "" } + +#include <fstream> +#include <filesystem> +#include <testsuite_hooks.h> + +const std::filesystem::path filename = "ofstream_members-1.tst"; + +void +test01() +{ + std::fstream f; + f.open(filename); + VERIFY( f.is_open() ); +} + +void +test02() +{ + std::fstream f; + f.open(filename, std::ios::in|std::ios::out); + VERIFY( f.is_open() ); +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ifstream/cons/char/path.cc b/libstdc++-v3/testsuite/27_io/basic_ifstream/cons/char/path.cc new file mode 100644 index 00000000000..24286f5eeaf --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ifstream/cons/char/path.cc @@ -0,0 +1,48 @@ +// Copyright (C) 2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-fileio "" } +// { dg-require-filesystem-ts "" } + +#include <fstream> +#include <filesystem> +#include <testsuite_hooks.h> + +const std::filesystem::path filename = "ifstream_members-1.tst"; + +void +test01() +{ + std::ifstream f(filename); + VERIFY( f.is_open() ); +} + +void +test02() +{ + std::ifstream f(filename, std::ios::in); + VERIFY( f.is_open() ); +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ifstream/open/char/path.cc b/libstdc++-v3/testsuite/27_io/basic_ifstream/open/char/path.cc new file mode 100644 index 00000000000..192e0fe9e85 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ifstream/open/char/path.cc @@ -0,0 +1,50 @@ +// Copyright (C) 2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-fileio "" } +// { dg-require-filesystem-ts "" } + +#include <fstream> +#include <filesystem> +#include <testsuite_hooks.h> + +const std::filesystem::path filename = "ifstream_members-1.tst"; + +void +test01() +{ + std::ifstream f; + f.open(filename); + VERIFY( f.is_open() ); +} + +void +test02() +{ + std::ifstream f; + f.open(filename, std::ios::in); + VERIFY( f.is_open() ); +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ofstream/cons/char/path.cc b/libstdc++-v3/testsuite/27_io/basic_ofstream/cons/char/path.cc new file mode 100644 index 00000000000..c6b6b237dfd --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ofstream/cons/char/path.cc @@ -0,0 +1,48 @@ +// Copyright (C) 2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-fileio "" } +// { dg-require-filesystem-ts "" } + +#include <fstream> +#include <filesystem> +#include <testsuite_hooks.h> + +const std::filesystem::path filename = "ofstream_members-1.tst"; + +void +test01() +{ + std::ofstream f(filename); + VERIFY( f.is_open() ); +} + +void +test02() +{ + std::ofstream f(filename, std::ios::out); + VERIFY( f.is_open() ); +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ofstream/open/char/path.cc b/libstdc++-v3/testsuite/27_io/basic_ofstream/open/char/path.cc new file mode 100644 index 00000000000..a3fc0c7ff68 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ofstream/open/char/path.cc @@ -0,0 +1,50 @@ +// Copyright (C) 2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-fileio "" } +// { dg-require-filesystem-ts "" } + +#include <fstream> +#include <filesystem> +#include <testsuite_hooks.h> + +const std::filesystem::path filename = "ofstream_members-1.tst"; + +void +test01() +{ + std::ofstream f; + f.open(filename); + VERIFY( f.is_open() ); +} + +void +test02() +{ + std::ofstream f; + f.open(filename, std::ios::out); + VERIFY( f.is_open() ); +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/file_status/1.cc b/libstdc++-v3/testsuite/27_io/filesystem/file_status/1.cc new file mode 100644 index 00000000000..21613020f88 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/file_status/1.cc @@ -0,0 +1,84 @@ +// Copyright (C) 2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +#include <filesystem> +#include <testsuite_hooks.h> + +namespace fs = std::filesystem; + +template<typename... Args> +constexpr bool nothrow_constructible() { + return std::is_nothrow_constructible<fs::file_status, Args...>::value; +} + +void +test01() +{ + fs::file_status st0; + VERIFY( st0.type() == fs::file_type::none ); + VERIFY( st0.permissions() == fs::perms::unknown ); + static_assert( nothrow_constructible<>(), "" ); + + fs::file_status st1(fs::file_type::regular); + VERIFY( st1.type() == fs::file_type::regular ); + VERIFY( st1.permissions() == fs::perms::unknown ); + static_assert( nothrow_constructible<fs::file_type>(), "" ); + + fs::file_status st2(fs::file_type::directory, fs::perms::owner_all); + VERIFY( st2.type() == fs::file_type::directory ); + VERIFY( st2.permissions() == fs::perms::owner_all ); + static_assert( nothrow_constructible<fs::file_type, fs::perms>(), "" ); + + static_assert( nothrow_constructible<const fs::file_status&>(), "" ); + static_assert( nothrow_constructible<fs::file_status>(), "" ); +} + +void +test02() +{ + fs::file_status st; + VERIFY( st.type() == fs::file_type::none ); + VERIFY( st.permissions() == fs::perms::unknown ); + + st.type(fs::file_type::symlink); + VERIFY( st.type() == fs::file_type::symlink ); + VERIFY( st.permissions() == fs::perms::unknown ); + + st.permissions(fs::perms::owner_all); + VERIFY( st.type() == fs::file_type::symlink ); + VERIFY( st.permissions() == fs::perms::owner_all ); +} + +void check_non_explicit_constructor(fs::file_status) { } + +void +test03() +{ + check_non_explicit_constructor( {} ); // LWG 2787 +} + +int +main() +{ + test01(); + test02(); + test03(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/iterators/directory_iterator.cc b/libstdc++-v3/testsuite/27_io/filesystem/iterators/directory_iterator.cc new file mode 100644 index 00000000000..c3e6f01670a --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/iterators/directory_iterator.cc @@ -0,0 +1,150 @@ +// Copyright (C) 2015-2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +#include <filesystem> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +namespace fs = std::filesystem; + +void +test01() +{ + const std::error_code bad_ec = make_error_code(std::errc::invalid_argument); + std::error_code ec; + + // Test non-existent path. + const auto p = __gnu_test::nonexistent_path(); + fs::directory_iterator iter(p, ec); + VERIFY( ec ); + VERIFY( iter == end(iter) ); + + // Test empty directory. + create_directory(p, fs::current_path(), ec); + VERIFY( !ec ); + ec = bad_ec; + iter = fs::directory_iterator(p, ec); + VERIFY( !ec ); + VERIFY( iter == end(iter) ); + + // Test non-empty directory. + ec = bad_ec; + create_directory_symlink(p, p / "l", ec); + VERIFY( !ec ); + ec = bad_ec; + iter = fs::directory_iterator(p, ec); + VERIFY( !ec ); + VERIFY( iter != fs::directory_iterator() ); + VERIFY( iter->path() == p/"l" ); + ++iter; + VERIFY( iter == end(iter) ); + + // Test inaccessible directory. + ec = bad_ec; + permissions(p, fs::perms::none, ec); + VERIFY( !ec ); + ec = bad_ec; + iter = fs::directory_iterator(p, ec); + VERIFY( ec ); + VERIFY( iter == end(iter) ); + + // Test inaccessible directory, skipping permission denied. + const auto opts = fs::directory_options::skip_permission_denied; + ec = bad_ec; + iter = fs::directory_iterator(p, opts, ec); + VERIFY( !ec ); + VERIFY( iter == end(iter) ); + + permissions(p, fs::perms::owner_all, ec); + remove_all(p, ec); +} + +void +test02() +{ + const std::error_code bad_ec = make_error_code(std::errc::invalid_argument); + std::error_code ec; + const auto p = __gnu_test::nonexistent_path(); + ec = bad_ec; + create_directory(p, fs::current_path(), ec); + create_directory_symlink(p, p / "l", ec); + VERIFY( !ec ); + + // Test post-increment (libstdc++/71005) + ec = bad_ec; + auto iter = fs::directory_iterator(p, ec); + VERIFY( !ec ); + VERIFY( iter != end(iter) ); + const auto entry1 = *iter; + const auto entry2 = *iter++; + VERIFY( entry1 == entry2 ); + VERIFY( entry1.path() == p/"l" ); + VERIFY( iter == end(iter) ); + + remove_all(p, ec); +} + +void +test03() +{ + std::error_code ec = make_error_code(std::errc::invalid_argument); + const auto p = __gnu_test::nonexistent_path(); + create_directories(p / "longer_than_small_string_buffer", ec); + VERIFY( !ec ); + + // Test for no reallocation on each dereference (this is a GNU extension) + auto iter = fs::directory_iterator(p, ec); + const auto* s1 = iter->path().c_str(); + const auto* s2 = iter->path().c_str(); + VERIFY( s1 == s2 ); + + remove_all(p, ec); +} + +void +test04() +{ + const fs::directory_iterator it; + VERIFY( it == fs::directory_iterator() ); +} + +void +test05() +{ + 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/27_io/filesystem/iterators/pop.cc b/libstdc++-v3/testsuite/27_io/filesystem/iterators/pop.cc new file mode 100644 index 00000000000..02dc04f2ba9 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/iterators/pop.cc @@ -0,0 +1,117 @@ +// Copyright (C) 2016-2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +#include <filesystem> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +namespace fs = std::filesystem; + +void +test01() +{ + std::error_code ec; + fs::recursive_directory_iterator dir; + dir.pop(ec); // This is undefined, but our implementation + VERIFY( ec ); // checks and returns an error. + VERIFY( dir == end(dir) ); + + std::error_code ec2; + try + { + dir.pop(); + } + catch (const fs::filesystem_error& ex) + { + ec2 = ex.code(); + } + VERIFY( ec2 == ec ); +} + +void +test02() +{ + const std::error_code bad_ec = make_error_code(std::errc::invalid_argument); + std::error_code ec; + const auto p = __gnu_test::nonexistent_path(); + create_directories(p / "d1/d2/d3"); + for (int i = 0; i < 3; ++i) + { + fs::recursive_directory_iterator dir(p); + VERIFY( dir != end(dir) ); + std::advance(dir, i); + VERIFY( dir != end(dir) ); + VERIFY( dir.depth() == i ); + ec = bad_ec; + dir.pop(ec); + VERIFY( !ec ); + VERIFY( dir == end(dir) ); + + dir = fs::recursive_directory_iterator(p); + std::advance(dir, i); + VERIFY( dir != end(dir) ); + VERIFY( dir.depth() == i ); + dir.pop(); + VERIFY( dir == end(dir) ); + } + remove_all(p, ec); +} + +void +test03() +{ + const std::error_code bad_ec = make_error_code(std::errc::invalid_argument); + std::error_code ec; + const auto p = __gnu_test::nonexistent_path(); + create_directories(p / "d1/d2/d3"); + create_directories(p / "d1/d2/e3"); + create_directories(p / "d1/e2/d3"); + for (int i = 0; i < 3; ++i) + { + fs::recursive_directory_iterator dir(p); + std::advance(dir, i); + VERIFY( dir != end(dir) ); + int expected_depth = i; + VERIFY( dir.depth() == expected_depth ); + ec = bad_ec; + dir.pop(ec); + VERIFY( !ec ); + if (dir != end(dir)) + VERIFY( dir.depth() == (expected_depth - 1) ); + + dir = fs::recursive_directory_iterator(p); + std::advance(dir, i); + VERIFY( dir != end(dir) ); + VERIFY( dir.depth() == i ); + dir.pop(); + if (dir != end(dir)) + VERIFY( dir.depth() == (i -1) ); + } + remove_all(p, ec); +} + +int +main() +{ + test01(); + test02(); + test03(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/iterators/recursive_directory_iterator.cc b/libstdc++-v3/testsuite/27_io/filesystem/iterators/recursive_directory_iterator.cc new file mode 100644 index 00000000000..1ef450fc907 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/iterators/recursive_directory_iterator.cc @@ -0,0 +1,188 @@ +// Copyright (C) 2015-2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +#include <filesystem> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +namespace fs = std::filesystem; + +void +test01() +{ + const std::error_code bad_ec = make_error_code(std::errc::invalid_argument); + std::error_code ec; + + // Test non-existent path. + const auto p = __gnu_test::nonexistent_path(); + fs::recursive_directory_iterator iter(p, ec); + VERIFY( ec ); + VERIFY( iter == end(iter) ); + + // Test empty directory. + ec = bad_ec; + create_directory(p, fs::current_path(), ec); + VERIFY( !ec ); + ec = bad_ec; + iter = fs::recursive_directory_iterator(p, ec); + VERIFY( !ec ); + VERIFY( iter == end(iter) ); + + // Test non-empty directory. + ec = bad_ec; + create_directories(p / "d1/d2", ec); + VERIFY( !ec ); + ec = bad_ec; + iter = fs::recursive_directory_iterator(p, ec); + VERIFY( !ec ); + VERIFY( iter != end(iter) ); + VERIFY( iter->path() == p/"d1" ); + ++iter; + VERIFY( iter->path() == p/"d1/d2" ); + ++iter; + VERIFY( iter == end(iter) ); + + // Test inaccessible directory. + ec = bad_ec; + permissions(p, fs::perms::none, ec); + VERIFY( !ec ); + iter = fs::recursive_directory_iterator(p, ec); + VERIFY( ec ); + VERIFY( iter == end(iter) ); + + // Test inaccessible directory, skipping permission denied. + const auto opts = fs::directory_options::skip_permission_denied; + iter = fs::recursive_directory_iterator(p, opts, ec); + VERIFY( !ec ); + VERIFY( iter == end(iter) ); + + // Test inaccessible sub-directory. + ec = bad_ec; + permissions(p, fs::perms::owner_all, ec); + VERIFY( !ec ); + ec = bad_ec; + permissions(p/"d1/d2", fs::perms::none, ec); + VERIFY( !ec ); + ec = bad_ec; + iter = fs::recursive_directory_iterator(p, ec); + VERIFY( !ec ); + VERIFY( iter != end(iter) ); + VERIFY( iter->path() == p/"d1" ); + ++iter; // should recurse into d1 + VERIFY( iter->path() == p/"d1/d2" ); + iter.increment(ec); // should fail to recurse into p/d1/d2 + VERIFY( ec ); + VERIFY( iter == end(iter) ); + + // Test inaccessible sub-directory, skipping permission denied. + ec = bad_ec; + iter = fs::recursive_directory_iterator(p, opts, ec); + VERIFY( !ec ); + VERIFY( iter != end(iter) ); + VERIFY( iter->path() == p/"d1" ); + ++iter; // should recurse into d1 + VERIFY( iter->path() == p/"d1/d2" ); + ec = bad_ec; + iter.increment(ec); // should fail to recurse into p/d1/d2, so skip it + VERIFY( !ec ); + VERIFY( iter == end(iter) ); + + permissions(p/"d1/d2", fs::perms::owner_all, ec); + remove_all(p, ec); +} + +void +test02() +{ + const std::error_code bad_ec = make_error_code(std::errc::invalid_argument); + std::error_code ec; + const auto p = __gnu_test::nonexistent_path(); + ec = bad_ec; + create_directories(p / "d1/d2", ec); + VERIFY( !ec ); + + // Test post-increment (libstdc++/71005) + ec = bad_ec; + auto iter = fs::recursive_directory_iterator(p, ec); + VERIFY( !ec ); + VERIFY( iter != end(iter) ); + const auto entry1 = *iter; + const auto entry2 = *iter++; + VERIFY( entry1 == entry2 ); + VERIFY( entry1.path() == p/"d1" ); + const auto entry3 = *iter; + const auto entry4 = *iter++; + VERIFY( entry3 == entry4 ); + VERIFY( entry3.path() == p/"d1/d2" ); + VERIFY( iter == end(iter) ); + + remove_all(p, ec); +} + +void +test03() +{ + const std::error_code bad_ec = make_error_code(std::errc::invalid_argument); + std::error_code ec; + const auto p = __gnu_test::nonexistent_path(); + ec = bad_ec; + create_directories(p / "longer_than_small_string_buffer", ec); + VERIFY( !ec ); + + // Test for no reallocation on each dereference (this is a GNU extension) + auto iter = fs::recursive_directory_iterator(p, ec); + const auto* s1 = iter->path().c_str(); + const auto* s2 = iter->path().c_str(); + VERIFY( s1 == s2 ); + + remove_all(p, ec); +} + +void +test04() +{ + // libstdc++/71004 + const fs::recursive_directory_iterator it; + VERIFY( it == end(it) ); +} + +void +test05() +{ + 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() +{ + test01(); + test02(); + test03(); + test04(); + test05(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/operations/absolute.cc b/libstdc++-v3/testsuite/27_io/filesystem/operations/absolute.cc new file mode 100644 index 00000000000..de1cd318f96 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/operations/absolute.cc @@ -0,0 +1,54 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// C++17 30.10.14.1 Absolute [fs.op.absolute] + +#include <filesystem> +#include <testsuite_fs.h> +#include <testsuite_hooks.h> + +using std::filesystem::path; + +void +test01() +{ + for (const path& p : __gnu_test::test_paths) + VERIFY( absolute(p).is_absolute() ); +} + +void +test02() +{ + path p1("/"); + VERIFY( absolute(p1) == p1 ); + path p2("/foo"); + VERIFY( absolute(p2) == p2 ); + path p3("foo"); + VERIFY( absolute(p3) != p3 ); + VERIFY( absolute(p3) == (std::filesystem::current_path()/p3) ); +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/operations/canonical.cc b/libstdc++-v3/testsuite/27_io/filesystem/operations/canonical.cc new file mode 100644 index 00000000000..47305a8f527 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/operations/canonical.cc @@ -0,0 +1,140 @@ +// Copyright (C) 2015-2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +#include <filesystem> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +namespace fs = std::filesystem; +using __gnu_test::compare_paths; + +void +test01() +{ + const std::error_code bad_ec = make_error_code(std::errc::invalid_argument); + std::error_code ec; + auto p = __gnu_test::nonexistent_path(); + canonical( p, ec ); + VERIFY( ec ); + + create_directory(p); + auto p2 = canonical( p, ec ); + compare_paths( p2, fs::current_path()/p ); + VERIFY( !ec ); + + ec = bad_ec; + p2 = canonical( fs::current_path() / "." / (p.native() + "////././."), ec ); + compare_paths( p2, fs::current_path()/p ); + VERIFY( !ec ); + + ec = bad_ec; + p = fs::current_path(); + p2 = canonical( p, ec ); + compare_paths( p2, p ); + VERIFY( !ec ); + + ec = bad_ec; + p = "/"; + p = canonical( p, ec ); + compare_paths( p, "/" ); + VERIFY( !ec ); + + ec = bad_ec; + p = "/."; + p = canonical( p, ec ); + compare_paths( p, "/" ); + VERIFY( !ec ); + + ec = bad_ec; + p = "/.."; + p = canonical( p, ec ); + compare_paths( p, "/" ); + VERIFY( !ec ); + + ec = bad_ec; + p = "/../.././."; + p = canonical( p, ec ); + compare_paths( p, "/" ); + VERIFY( !ec ); +} + +void +test02() +{ + const fs::path p = __gnu_test::nonexistent_path(); + std::error_code ec, ec2; + const fs::path res = canonical(p, ec); + VERIFY( ec ); + VERIFY( res.empty() ); + +#if __cpp_exceptions + fs::path e1, e2; + try { + canonical(p); + } catch (const fs::filesystem_error& e) { + e1 = e.path1(); + e2 = e.path2(); + ec2 = e.code(); + } + VERIFY( e1 == p ); + VERIFY( e2.empty() ); + VERIFY( ec == ec2 ); +#endif +} + + +void +test03() +{ + std::error_code ec; + auto dir = __gnu_test::nonexistent_path(); + fs::create_directory(dir); + fs::path foo = dir/"foo", bar = dir/"bar"; + fs::create_directory(foo); + fs::create_directory(bar); + fs::create_symlink("../bar", foo/"baz"); + + auto dirc = canonical(dir); + auto barc = canonical(bar); + + auto p1 = fs::canonical(dir/"foo//.///..//./"); + compare_paths( p1, dirc ); + auto p2 = fs::canonical(dir/"foo//./baz///..//./"); + compare_paths( p2, dirc ); + auto p3 = fs::canonical(dir/"foo//./baz////./"); + compare_paths( p3, barc ); + auto p4 = fs::canonical(dir/"foo//./baz///..//./bar"); + compare_paths( p4, barc ); + auto p5 = fs::canonical(dir/"foo//./baz///..//./bar/"); + compare_paths( p5, p4 ); + auto p6 = fs::canonical(dir/"foo//./baz///..//./bar/."); + compare_paths( p6, p4 ); + + remove_all(dir); +} + +int +main() +{ + test01(); + test02(); + test03(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/operations/copy.cc b/libstdc++-v3/testsuite/27_io/filesystem/operations/copy.cc new file mode 100644 index 00000000000..7825a4ef5dd --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/operations/copy.cc @@ -0,0 +1,200 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 15.3 Copy [fs.op.copy] + +#include <filesystem> +#include <testsuite_fs.h> +#include <testsuite_hooks.h> + +namespace fs = std::filesystem; + +// Test error conditions. +void +test01() +{ + auto p = __gnu_test::nonexistent_path(); + std::error_code ec; + + VERIFY( !fs::exists(p) ); + fs::copy(p, ".", fs::copy_options::none, ec); + VERIFY( ec ); + + ec.clear(); + fs::copy(".", ".", fs::copy_options::none, ec); + VERIFY( ec ); + + __gnu_test::scoped_file f(p); + VERIFY( fs::is_directory(".") ); + VERIFY( fs::is_regular_file(p) ); + ec.clear(); + fs::copy(".", p, fs::copy_options::none, ec); + VERIFY( ec ); + + auto to = __gnu_test::nonexistent_path(); + ec.clear(); + auto opts = fs::copy_options::create_symlinks; + fs::copy("/", to, opts, ec); + VERIFY( ec == std::make_error_code(std::errc::is_a_directory) ); + VERIFY( !exists(to) ); + + ec.clear(); + opts != fs::copy_options::recursive; + fs::copy("/", to, opts, ec); + VERIFY( ec == std::make_error_code(std::errc::is_a_directory) ); + VERIFY( !exists(to) ); +} + +// Test is_symlink(f) case. +void +test02() +{ + const std::error_code bad_ec = make_error_code(std::errc::invalid_argument); + auto from = __gnu_test::nonexistent_path(); + auto to = __gnu_test::nonexistent_path(); + std::error_code ec; + + ec = bad_ec; + fs::create_symlink(".", from, ec); + VERIFY( !ec ); + VERIFY( fs::exists(from) ); + + ec = bad_ec; + fs::copy(from, to, fs::copy_options::skip_symlinks, ec); + VERIFY( !ec ); + VERIFY( !fs::exists(to) ); + + ec = bad_ec; + fs::copy(from, to, fs::copy_options::skip_symlinks, ec); + VERIFY( !ec ); + VERIFY( !fs::exists(to) ); + + ec = bad_ec; + fs::copy(from, to, + fs::copy_options::skip_symlinks|fs::copy_options::copy_symlinks, + ec); + VERIFY( !ec ); + VERIFY( !fs::exists(to) ); + + ec = bad_ec; + fs::copy(from, to, fs::copy_options::copy_symlinks, ec); + VERIFY( !ec ); + VERIFY( fs::exists(to) ); + VERIFY( is_symlink(to) ); + + ec.clear(); + fs::copy(from, to, fs::copy_options::copy_symlinks, ec); + VERIFY( ec ); + + remove(from, ec); + remove(to, ec); +} + +// Test is_regular_file(f) case. +void +test03() +{ + auto from = __gnu_test::nonexistent_path(); + auto to = __gnu_test::nonexistent_path(); + + // test empty file + std::ofstream{from.native()}; + VERIFY( fs::exists(from) ); + VERIFY( fs::file_size(from) == 0 ); + fs::copy(from, to); + VERIFY( fs::exists(to) ); + VERIFY( fs::file_size(to) == 0 ); + + remove(to); + VERIFY( !fs::exists(to) ); + std::ofstream{from.native()} << "Hello, filesystem!"; + VERIFY( fs::file_size(from) != 0 ); + fs::copy(from, to); + VERIFY( fs::exists(to) ); + VERIFY( fs::file_size(to) == fs::file_size(from) ); + + remove(from); + remove(to); +} + +// Test is_directory(f) case. +void +test04() +{ + const std::error_code bad_ec = make_error_code(std::errc::invalid_argument); + auto from = __gnu_test::nonexistent_path(); + auto to = __gnu_test::nonexistent_path(); + std::error_code ec; + + create_directories(from/"a/b/c"); + + { + __gnu_test::scoped_file f(to); + copy(from, to, ec); + VERIFY( ec ); + } + + __gnu_test::scoped_file f1(from/"a/f1"); + std::ofstream{f1.path} << "file one"; + __gnu_test::scoped_file f2(from/"a/b/f2"); + std::ofstream{f2.path} << "file two"; + + copy(from, to, ec); + VERIFY( !ec ); + VERIFY( exists(to) && is_empty(to) ); + remove(to); + + ec = bad_ec; + copy(from, to, fs::copy_options::recursive, ec); + VERIFY( !ec ); + VERIFY( exists(to) && !is_empty(to) ); + VERIFY( is_regular_file(to/"a/f1") && !is_empty(to/"a/f1") ); + VERIFY( file_size(from/"a/f1") == file_size(to/"a/f1") ); + VERIFY( is_regular_file(to/"a/b/f2") && !is_empty(to/"a/b/f2") ); + VERIFY( file_size(from/"a/b/f2") == file_size(to/"a/b/f2") ); + VERIFY( is_directory(to/"a/b/c") && is_empty(to/"a/b/c") ); + + f1.path.clear(); + f2.path.clear(); + remove_all(from, ec); + remove_all(to, ec); +} + +// Test no-op cases. +void +test05() +{ + auto to = __gnu_test::nonexistent_path(); + std::error_code ec = std::make_error_code(std::errc::invalid_argument); + + fs::copy("/", to, fs::copy_options::copy_symlinks, ec); + VERIFY( !ec ); // Previous value should be cleared (LWG 2683) +} + +int +main() +{ + test01(); + test02(); + test03(); + test04(); + test05(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/operations/copy_file.cc b/libstdc++-v3/testsuite/27_io/filesystem/operations/copy_file.cc new file mode 100644 index 00000000000..69ab7fbab8d --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/operations/copy_file.cc @@ -0,0 +1,84 @@ +// Copyright (C) 2016-2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// 15.4 Copy [fs.op.copy_file] + +#include <filesystem> +#include <fstream> +#include <testsuite_fs.h> +#include <testsuite_hooks.h> + +void +test01() +{ + using std::filesystem::copy_options; + std::error_code ec; + + auto from = __gnu_test::nonexistent_path(); + auto to = __gnu_test::nonexistent_path(); + + // test non-existent file + bool b = copy_file(from, to, ec); + VERIFY( !b ); + VERIFY( ec ); + VERIFY( !exists(to) ); + + // test empty file + std::ofstream{from.native()}; + VERIFY( exists(from) ); + VERIFY( file_size(from) == 0 ); + + b = copy_file(from, to); + VERIFY( b ); + VERIFY( exists(to) ); + VERIFY( file_size(to) == 0 ); + remove(to); + VERIFY( !exists(to) ); + b = copy_file(from, to, copy_options::none, ec); + VERIFY( b ); + VERIFY( !ec ); + VERIFY( exists(to) ); + VERIFY( file_size(to) == 0 ); + + std::ofstream{from.native()} << "Hello, filesystem!"; + VERIFY( file_size(from) != 0 ); + remove(to); + VERIFY( !exists(to) ); + b = copy_file(from, to); + VERIFY( b ); + VERIFY( exists(to) ); + VERIFY( file_size(to) == file_size(from) ); + remove(to); + VERIFY( !exists(to) ); + b = copy_file(from, to); + VERIFY( b ); + VERIFY( exists(to) ); + VERIFY( file_size(to) == file_size(from) ); + + remove(from); + remove(to); +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/operations/create_directories.cc b/libstdc++-v3/testsuite/27_io/filesystem/operations/create_directories.cc new file mode 100644 index 00000000000..94596787196 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/operations/create_directories.cc @@ -0,0 +1,83 @@ +// Copyright (C) 2015-2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +#include <filesystem> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +namespace fs = std::filesystem; + +void +test01() +{ + const std::error_code bad_ec = make_error_code(std::errc::invalid_argument); + std::error_code ec; + + // Test empty path. + bool b = fs::create_directories( "", ec ); + VERIFY( ec ); + VERIFY( !b ); + + // Test existing path. + ec = bad_ec; + b = fs::create_directories( fs::current_path(), ec ); + VERIFY( !ec ); + VERIFY( !b ); + + // Test non-existent path. + const auto p = __gnu_test::nonexistent_path(); + ec = bad_ec; + b = fs::create_directories( p, ec ); + VERIFY( !ec ); + VERIFY( b ); + VERIFY( is_directory(p) ); + + ec = bad_ec; + b = fs::create_directories( p/".", ec ); + VERIFY( !ec ); + VERIFY( !b ); + + ec = bad_ec; + b = fs::create_directories( p/"..", ec ); + VERIFY( !ec ); + VERIFY( !b ); + + ec = bad_ec; + b = fs::create_directories( p/"d1/d2/d3", ec ); + VERIFY( !ec ); + VERIFY( b ); + VERIFY( is_directory(p/"d1/d2/d3") ); + + ec = bad_ec; + b = fs::create_directories( p/"./d4/../d5", ec ); + VERIFY( !ec ); + VERIFY( b ); + VERIFY( is_directory(p/"./d4/../d5") ); + + std::uintmax_t count = remove_all(p, ec); + VERIFY( count == 6 ); +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/operations/create_directory.cc b/libstdc++-v3/testsuite/27_io/filesystem/operations/create_directory.cc new file mode 100644 index 00000000000..927a97c7a84 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/operations/create_directory.cc @@ -0,0 +1,65 @@ +// Copyright (C) 2016-2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +#include <filesystem> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +namespace fs = std::filesystem; + +void +test01() +{ + const std::error_code bad_ec = make_error_code(std::errc::invalid_argument); + std::error_code ec; + + // Test empty path. + fs::path p; + bool b = create_directory( p, ec ); + VERIFY( ec ); + VERIFY( !b ); + + // Test non-existent path + p = __gnu_test::nonexistent_path(); + VERIFY( !exists(p) ); + + ec = bad_ec; + b = create_directory(p, ec); // create the directory once + VERIFY( !ec ); + VERIFY( b ); + VERIFY( exists(p) ); + + // Test existing path (libstdc++/71036). + ec = bad_ec; + b = create_directory(p, ec); + VERIFY( !ec ); + VERIFY( !b ); + b = create_directory(p); + VERIFY( !b ); + + remove_all(p, ec); +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/operations/create_symlink.cc b/libstdc++-v3/testsuite/27_io/filesystem/operations/create_symlink.cc new file mode 100644 index 00000000000..7eff356b883 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/operations/create_symlink.cc @@ -0,0 +1,96 @@ +// Copyright (C) 2016-2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +#include <filesystem> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +namespace fs = std::filesystem; + +void +test01() +{ + std::error_code ec, ec2; + __gnu_test::scoped_file f; + auto tgt = f.path; + + // Test empty path. + fs::path p; + create_symlink(tgt, p, ec ); + VERIFY( ec ); + try + { + create_symlink(tgt, p); + } + catch (const std::filesystem::filesystem_error& ex) + { + ec2 = ex.code(); + VERIFY( ex.path1() == tgt ); + VERIFY( ex.path2() == p ); + } + VERIFY( ec2 == ec ); +} + +void +test02() +{ + const std::error_code bad_ec = make_error_code(std::errc::invalid_argument); + std::error_code ec, ec2; + __gnu_test::scoped_file f; + auto tgt = f.path; + + // Test non-existent path + auto p = __gnu_test::nonexistent_path(); + VERIFY( !exists(p) ); + + ec = bad_ec; + create_symlink(tgt, p, ec); // create the symlink once + VERIFY( !ec ); + VERIFY( exists(p) ); + VERIFY( is_symlink(p) ); + remove(p); + create_symlink(tgt, p); // create the symlink again + VERIFY( exists(p) ); + VERIFY( is_symlink(p) ); + + ec.clear(); + create_symlink(tgt, p, ec); // Try to create existing symlink + VERIFY( ec ); + try + { + create_symlink(tgt, p); + } + catch (const std::filesystem::filesystem_error& ex) + { + ec2 = ex.code(); + VERIFY( ex.path1() == tgt ); + VERIFY( ex.path2() == p ); + } + VERIFY( ec2 == ec ); + + remove(p); +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/operations/current_path.cc b/libstdc++-v3/testsuite/27_io/filesystem/operations/current_path.cc new file mode 100644 index 00000000000..2ba3ff9fc53 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/operations/current_path.cc @@ -0,0 +1,58 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 15.11 Current path [fs.op.current_path] + +#include <filesystem> +#include <testsuite_fs.h> +#include <testsuite_hooks.h> + +namespace fs = std::filesystem; + +void +test01() +{ + fs::path dot("."); + fs::path cwd = fs::current_path(); + std::error_code ec; + fs::path cwd2 = fs::current_path(ec); + VERIFY( cwd == cwd2 ); +} + +void +test02() +{ + auto oldwd = fs::current_path(); + auto tmpdir = fs::temp_directory_path(); + current_path(tmpdir); + VERIFY( canonical(fs::current_path()) == canonical(tmpdir) ); + std::error_code ec; + current_path(oldwd, ec); + VERIFY( canonical(fs::current_path()) == canonical(oldwd) ); + VERIFY( canonical(fs::current_path(ec)) == canonical(oldwd) ); +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/operations/equivalent.cc b/libstdc++-v3/testsuite/27_io/filesystem/operations/equivalent.cc new file mode 100644 index 00000000000..92d69c604ac --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/operations/equivalent.cc @@ -0,0 +1,74 @@ +// Copyright (C) 2016-2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +#include <filesystem> +#include <testsuite_fs.h> +#include <testsuite_hooks.h> + +namespace fs = std::filesystem; + +void +test01() +{ + auto p1 = __gnu_test::nonexistent_path(); + auto p2 = __gnu_test::nonexistent_path(); + const std::error_code bad_ec = make_error_code(std::errc::invalid_argument); + std::error_code ec; + bool result; + + result = equivalent(p1, p2, ec); + VERIFY( ec ); + VERIFY( !result ); + + __gnu_test::scoped_file f1(p1); + ec = bad_ec; + result = equivalent(p1, p2, ec); + VERIFY( !ec ); + VERIFY( !result ); + + __gnu_test::scoped_file f2(p2); + ec = bad_ec; + result = equivalent(p1, p2, ec); + VERIFY( !ec ); + VERIFY( !result ); + + auto p3 = __gnu_test::nonexistent_path(); + create_hard_link(p1, p3, ec); + if (ec) + return; // hard links not supported + __gnu_test::scoped_file f3(p3, __gnu_test::scoped_file::adopt_file); + + ec = bad_ec; + result = equivalent(p1, p3, ec); + VERIFY( !ec ); + VERIFY( result ); + + ec = bad_ec; + result = equivalent(p2, p3, ec); + VERIFY( !ec ); + VERIFY( !result ); +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/operations/exists.cc b/libstdc++-v3/testsuite/27_io/filesystem/operations/exists.cc new file mode 100644 index 00000000000..0775eff4d9b --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/operations/exists.cc @@ -0,0 +1,115 @@ +// Copyright (C) 2015-2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +#include <filesystem> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +using std::filesystem::path; + +void +test01() +{ + const std::error_code bad_ec = make_error_code(std::errc::invalid_argument); + + VERIFY( exists(path{"/"}) ); + VERIFY( exists(path{"/."}) ); + VERIFY( exists(path{"."}) ); + VERIFY( exists(path{".."}) ); + VERIFY( exists(std::filesystem::current_path()) ); + + std::error_code ec; + ec = bad_ec; + VERIFY( exists(path{"/"}, ec) ); + VERIFY( !ec ); + ec = bad_ec; + VERIFY( exists(path{"/."}, ec) ); + VERIFY( !ec ); + ec = bad_ec; + VERIFY( exists(path{"."}, ec) ); + VERIFY( !ec ); + ec = bad_ec; + VERIFY( exists(path{".."}, ec) ); + VERIFY( !ec ); + ec = bad_ec; + VERIFY( exists(std::filesystem::current_path(), ec) ); + VERIFY( !ec ); +} + +void +test02() +{ + path rel = __gnu_test::nonexistent_path(); + VERIFY( !exists(rel) ); + + std::error_code ec = std::make_error_code(std::errc::invalid_argument); + VERIFY( !exists(rel, ec) ); + VERIFY( !ec ); // DR 2725 +} + +void +test03() +{ + path abs = absolute(__gnu_test::nonexistent_path()); + VERIFY( !exists(abs) ); + + std::error_code ec = std::make_error_code(std::errc::invalid_argument); + VERIFY( !exists(abs, ec) ); + VERIFY( !ec ); // DR 2725 +} + +void +test04() +{ + using std::filesystem::perms; + using std::filesystem::perm_options; + path p = __gnu_test::nonexistent_path(); + create_directory(p); + permissions(p, perms::all, perm_options::remove); + + auto unr = p / "unreachable"; + std::error_code ec; + VERIFY( !exists(unr, ec) ); + VERIFY( ec == std::errc::permission_denied ); + ec.clear(); + try + { + exists(unr); + } + catch(const std::filesystem::filesystem_error& ex) + { + ec = ex.code(); + VERIFY( ex.path1() == unr ); + } + VERIFY( ec == std::errc::permission_denied ); + + permissions(p, perms::owner_all); + remove(p); +} + +int +main() +{ + test01(); + test02(); + test03(); + test04(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/operations/file_size.cc b/libstdc++-v3/testsuite/27_io/filesystem/operations/file_size.cc new file mode 100644 index 00000000000..250d31891a0 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/operations/file_size.cc @@ -0,0 +1,71 @@ +// Copyright (C) 2015-2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +#include <filesystem> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +namespace fs = std::filesystem; + +void +test01() +{ + std::error_code ec; + size_t size = fs::file_size(".", ec); + VERIFY( ec == std::errc::is_a_directory ); + VERIFY( size == -1 ); + + try { + size = fs::file_size("."); + ec.clear(); + } catch (const fs::filesystem_error& e) { + ec = e.code(); + } + VERIFY( ec == std::errc::is_a_directory ); + VERIFY( size == -1 ); +} + +void +test02() +{ + fs::path p = __gnu_test::nonexistent_path(); + + std::error_code ec; + size_t size = fs::file_size(p, ec); + VERIFY( ec ); + VERIFY( size == -1 ); + + try { + size = fs::file_size(p); + ec.clear(); + } catch (const fs::filesystem_error& e) { + ec = e.code(); + } + VERIFY( ec ); + VERIFY( size == -1 ); +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/operations/is_empty.cc b/libstdc++-v3/testsuite/27_io/filesystem/operations/is_empty.cc new file mode 100644 index 00000000000..6d79a9139cf --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/operations/is_empty.cc @@ -0,0 +1,109 @@ +// Copyright (C) 2016-2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +#include <filesystem> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +namespace fs = std::filesystem; + +void +test01() +{ + auto p = __gnu_test::nonexistent_path(); + create_directory(p); + permissions(p, fs::perms::none); + std::error_code ec, ec2; + + bool result = fs::is_empty(p, ec); + VERIFY( ec == std::make_error_code(std::errc::permission_denied) ); + VERIFY( !result ); + + try { + fs::is_empty(p); + } catch (const fs::filesystem_error& e) { + ec2 = e.code(); + } + VERIFY( ec2 == ec ); + + result = fs::is_empty(p/"f", ec); + VERIFY( ec == std::make_error_code(std::errc::permission_denied) ); + VERIFY( !result ); + + try { + fs::is_empty(p/"f"); + } catch (const fs::filesystem_error& e) { + ec2 = e.code(); + } + VERIFY( ec2 == ec ); + + permissions(p, fs::perms::owner_all, ec); + remove_all(p, ec); +} + +void +test02() +{ + auto p = __gnu_test::nonexistent_path(); + create_directory(p); + std::error_code ec, bad_ec = make_error_code(std::errc::invalid_argument); + bool empty; + + ec = bad_ec; + empty = is_empty(p, ec); + VERIFY( !ec ); + VERIFY( empty ); + empty = is_empty(p); + VERIFY( empty ); + + __gnu_test::scoped_file f(p/"f"); + ec = bad_ec; + empty = is_empty(f.path, ec); + VERIFY( !ec ); + VERIFY( empty ); + empty = is_empty(f.path); + VERIFY( empty ); + + std::ofstream{f.path.native()} << "data"; + ec = bad_ec; + empty = is_empty(p, ec); + VERIFY( !ec ); + VERIFY( !empty ); + empty = is_empty(p); + VERIFY( !empty ); + + ec = bad_ec; + empty = is_empty(p, ec); + VERIFY( !ec ); + VERIFY( !empty ); + empty = is_empty(p); + VERIFY( !empty ); + + f.path.clear(); + remove_all(p, ec); +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/operations/last_write_time.cc b/libstdc++-v3/testsuite/27_io/filesystem/operations/last_write_time.cc new file mode 100644 index 00000000000..ecef3f85721 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/operations/last_write_time.cc @@ -0,0 +1,162 @@ +// Copyright (C) 2016-2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// 15.25 Permissions [fs.op.last_write_time] + +#include <filesystem> +#include <testsuite_fs.h> +#include <testsuite_hooks.h> + +#ifdef _GLIBCXX_HAVE_FCNTL_H +# include <fcntl.h> +#endif +#if _GLIBCXX_HAVE_UTIME_H +# include <utime.h> +#endif + +using time_type = std::filesystem::file_time_type; + +void +test01() +{ + // read times + + auto p = __gnu_test::nonexistent_path(); + std::error_code ec; + time_type mtime = last_write_time(p, ec); + VERIFY( ec ); + VERIFY( ec == std::make_error_code(std::errc::no_such_file_or_directory) ); +#if __cpp_exceptions + bool caught = false; + try { + mtime = last_write_time(p); + } catch (std::system_error const& e) { + caught = true; + ec = e.code(); + } + VERIFY( caught ); + VERIFY( ec ); + VERIFY( ec == std::make_error_code(std::errc::no_such_file_or_directory) ); +#endif + + __gnu_test::scoped_file file(p); + VERIFY( exists(p) ); + mtime = last_write_time(p, ec); + VERIFY( !ec ); + VERIFY( mtime <= time_type::clock::now() ); + VERIFY( mtime == last_write_time(p) ); + + auto end_of_time = time_type::duration::max(); + auto last_second + = std::chrono::duration_cast<std::chrono::seconds>(end_of_time).count(); + if (last_second > std::numeric_limits<std::time_t>::max()) + return; // can't test overflow + +#if _GLIBCXX_USE_UTIMENSAT + struct ::timespec ts[2]; + ts[0].tv_sec = 0; + ts[0].tv_nsec = UTIME_NOW; + ts[1].tv_sec = std::numeric_limits<std::time_t>::max() - 1; + ts[1].tv_nsec = 0; + VERIFY( !::utimensat(AT_FDCWD, p.c_str(), ts, 0) ); +#elif _GLIBCXX_HAVE_UTIME_H + ::utimbuf times; + times.modtime = std::numeric_limits<std::time_t>::max() - 1; + times.actime = std::numeric_limits<std::time_t>::max() - 1; + VERIFY( !::utime(p.c_str(), ×) ); +#else + return; +#endif + + mtime = last_write_time(p, ec); + VERIFY( ec ); + VERIFY( ec == std::make_error_code(std::errc::value_too_large) ); + VERIFY( mtime == time_type::min() ); + +#if __cpp_exceptions + caught = false; + try { + mtime = last_write_time(p); + } catch (std::system_error const& e) { + caught = true; + ec = e.code(); + } + VERIFY( caught ); + VERIFY( ec ); + VERIFY( ec == std::make_error_code(std::errc::value_too_large) ); +#endif +} + +bool approx_equal(time_type file_time, time_type expected) +{ + auto delta = expected - file_time; + if (delta < delta.zero()) + delta = -delta; + return delta < std::chrono::seconds(1); +} + +void +test02() +{ + // write times + + const std::error_code bad_ec = make_error_code(std::errc::invalid_argument); + __gnu_test::scoped_file f; + std::error_code ec; + time_type time; + + time = last_write_time(f.path); + ec = bad_ec; + last_write_time(f.path, time, ec); + VERIFY( !ec ); + VERIFY( approx_equal(last_write_time(f.path), time) ); + + ec = bad_ec; + time -= std::chrono::milliseconds(1000 * 60 * 10 + 15); + last_write_time(f.path, time, ec); + VERIFY( !ec ); + VERIFY( approx_equal(last_write_time(f.path), time) ); + + ec = bad_ec; + time += std::chrono::milliseconds(1000 * 60 * 20 + 15); + last_write_time(f.path, time, ec); + VERIFY( !ec ); + VERIFY( approx_equal(last_write_time(f.path), time) ); + + ec = bad_ec; + time = time_type(); + last_write_time(f.path, time, ec); + VERIFY( !ec ); + VERIFY( approx_equal(last_write_time(f.path), time) ); + + ec = bad_ec; + time -= std::chrono::milliseconds(1000 * 60 * 10 + 15); + last_write_time(f.path, time, ec); + VERIFY( !ec ); + VERIFY( approx_equal(last_write_time(f.path), time) ); +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/operations/permissions.cc b/libstdc++-v3/testsuite/27_io/filesystem/operations/permissions.cc new file mode 100644 index 00000000000..e190e886230 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/operations/permissions.cc @@ -0,0 +1,175 @@ +// Copyright (C) 2016-2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// C++17 30.10.14.26 Permissions [fs.op.permissions] + +#include <filesystem> +#include <testsuite_fs.h> +#include <testsuite_hooks.h> + +void +test01() +{ + using std::filesystem::perms; + using std::filesystem::perm_options; + + auto p = __gnu_test::nonexistent_path(); + + __gnu_test::scoped_file f(p); + VERIFY( exists(p) ); + permissions(p, perms::owner_all); + VERIFY( status(p).permissions() == perms::owner_all ); + permissions(p, perms::group_read, perm_options::add); + VERIFY( status(p).permissions() == (perms::owner_all | perms::group_read) ); + permissions(p, perms::group_read, perm_options::remove); + VERIFY( status(p).permissions() == perms::owner_all ); +} + +void +test02() +{ + const std::error_code bad_ec = make_error_code(std::errc::invalid_argument); + using std::filesystem::perms; + using std::filesystem::perm_options; + + auto p = __gnu_test::nonexistent_path(); + + std::error_code ec; + permissions(p, perms::owner_all, ec); + VERIFY( ec ); + + __gnu_test::scoped_file f(p); + VERIFY( exists(p) ); + + ec = bad_ec; + permissions(p, perms::owner_all, ec); + VERIFY( !ec ); + VERIFY( status(p).permissions() == perms::owner_all ); + ec = bad_ec; + permissions(p, perms::group_read, perm_options::add, ec); + VERIFY( !ec ); + VERIFY( status(p).permissions() == (perms::owner_all | perms::group_read) ); + ec = bad_ec; + permissions(p, perms::group_read, perm_options::remove, ec); + VERIFY( !ec ); + VERIFY( status(p).permissions() == perms::owner_all ); +} + +void +test03() +{ + using std::filesystem::perms; + using std::filesystem::perm_options; + + __gnu_test::scoped_file f; + VERIFY( exists(f.path) ); + + auto p = __gnu_test::nonexistent_path(); + create_symlink(f.path, p); + + std::error_code ec = make_error_code(std::errc::no_such_file_or_directory); + permissions(p, perms::owner_all, + perm_options::replace|perm_options::nofollow, ec); + bool caught = false; + std::error_code ec2; + try + { + permissions(p, perms::owner_all, + perm_options::replace|perm_options::nofollow); + } + catch (const std::filesystem::filesystem_error& ex) + { + caught = true; + ec2 = ex.code(); + VERIFY( ex.path1() == p ); + } + // Both calls should succeed, or both should fail with same error: + if (ec) + { + VERIFY( caught ); + VERIFY( ec == ec2 ); + } + else + VERIFY( !caught ); + + remove(p); +} + +void +test04() +{ + using perms = std::filesystem::perms; + + auto p = __gnu_test::nonexistent_path(); + create_symlink(__gnu_test::nonexistent_path(), p); + + std::error_code ec = make_error_code(std::errc::no_such_file_or_directory); + permissions(p, perms::owner_all, ec); + VERIFY( ec ); + std::error_code ec2; + try + { + permissions(p, perms::owner_all); + } + catch (const std::filesystem::filesystem_error& ex) + { + ec2 = ex.code(); + VERIFY( ex.path1() == p ); + } + VERIFY( ec == ec2 ); + + remove(p); +} + +void +test05() +{ + const std::error_code bad_ec = make_error_code(std::errc::invalid_argument); + using std::filesystem::perms; + using std::filesystem::perm_options; + std::error_code ec; + + __gnu_test::scoped_file f; + auto p = perms::owner_write; + + // symlink_nofollow should not give an error for non-symlinks + ec = bad_ec; + permissions(f.path, p, perm_options::replace|perm_options::nofollow, ec); + VERIFY( !ec ); + auto st = status(f.path); + VERIFY( st.permissions() == p ); + p |= perms::owner_read; + ec = bad_ec; + permissions(f.path, p, perm_options::replace|perm_options::nofollow, ec); + VERIFY( !ec ); + st = status(f.path); + VERIFY( st.permissions() == p ); +} + +int +main() +{ + test01(); + test02(); + test03(); + test04(); + test05(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/operations/proximate.cc b/libstdc++-v3/testsuite/27_io/filesystem/operations/proximate.cc new file mode 100644 index 00000000000..99b6568abeb --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/operations/proximate.cc @@ -0,0 +1,69 @@ +// Copyright (C) 2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +#include <filesystem> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +using std::filesystem::proximate; +using __gnu_test::compare_paths; + +void +test01() +{ + compare_paths( proximate("/a/d", "/a/b/c"), "../../d" ); + compare_paths( proximate("/a/b/c", "/a/d"), "../b/c" ); + compare_paths( proximate("a/b/c", "a"), "b/c" ); + compare_paths( proximate("a/b/c", "a/b/c/x/y"), "../.." ); + compare_paths( proximate("a/b/c", "a/b/c"), "." ); + compare_paths( proximate("a/b", "c/d"), "../../a/b" ); +} + +void +test02() +{ + const std::error_code bad_ec = make_error_code(std::errc::invalid_argument); + std::error_code ec = bad_ec; + compare_paths( proximate("/a/d", "/a/b/c", ec), "../../d" ); + VERIFY( !ec ); + ec = bad_ec; + compare_paths( proximate("/a/b/c", "/a/d", ec), "../b/c" ); + VERIFY( !ec ); + ec = bad_ec; + compare_paths( proximate("a/b/c", "a", ec), "b/c" ); + VERIFY( !ec ); + ec = bad_ec; + compare_paths( proximate("a/b/c", "a/b/c/x/y", ec), "../.." ); + VERIFY( !ec ); + ec = bad_ec; + compare_paths( proximate("a/b/c", "a/b/c", ec), "." ); + VERIFY( !ec ); + ec = bad_ec; + compare_paths( proximate("a/b", "c/d", ec), "../../a/b" ); + VERIFY( !ec ); +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/operations/read_symlink.cc b/libstdc++-v3/testsuite/27_io/filesystem/operations/read_symlink.cc new file mode 100644 index 00000000000..067a60950ea --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/operations/read_symlink.cc @@ -0,0 +1,51 @@ +// Copyright (C) 2016-2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +#include <filesystem> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +namespace fs = std::filesystem; + +void +test01() +{ + auto p = __gnu_test::nonexistent_path(); + std::error_code ec; + + read_symlink(p, ec); + VERIFY( ec ); + + fs::path tgt = "."; + create_symlink(tgt, p); + + auto result = read_symlink(p, ec); + VERIFY( !ec ); + VERIFY( result == tgt ); + + remove(p); +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/operations/relative.cc b/libstdc++-v3/testsuite/27_io/filesystem/operations/relative.cc new file mode 100644 index 00000000000..c9765fa5680 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/operations/relative.cc @@ -0,0 +1,64 @@ +// Copyright (C) 2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +#include <filesystem> +#include <testsuite_fs.h> +#include <testsuite_hooks.h> + +void +test01() +{ + auto p = __gnu_test::nonexistent_path(); + auto q = __gnu_test::nonexistent_path(); + + auto r = relative(p, q); + VERIFY( r == ".."/p ); + + r = relative(p, p/q); + VERIFY( r == ".." ); + + r = relative(p/q, p); + VERIFY( r == q ); + + const std::error_code bad_ec = make_error_code(std::errc::invalid_argument); + std::error_code ec; + + ec = bad_ec; + r = relative(p, q, ec); + VERIFY( !ec ); + VERIFY( r == ".."/p ); + + ec = bad_ec; + r = relative(p, p/q, ec); + VERIFY( !ec ); + VERIFY( r == ".." ); + + ec = bad_ec; + r = relative(p/q, p, ec); + VERIFY( !ec ); + VERIFY( r == q ); +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/operations/remove_all.cc b/libstdc++-v3/testsuite/27_io/filesystem/operations/remove_all.cc new file mode 100644 index 00000000000..3f68f17f992 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/operations/remove_all.cc @@ -0,0 +1,92 @@ +// Copyright (C) 2016-2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +#include <filesystem> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +namespace fs = std::filesystem; + +void +test01() +{ + std::error_code ec; + std::uintmax_t n; + + n = fs::remove_all("", ec); + VERIFY( ec ); + VERIFY( n == std::uintmax_t(-1) ); + + auto p = __gnu_test::nonexistent_path(); + ec.clear(); + n = remove_all(p, ec); + VERIFY( ec ); + VERIFY( n == std::uintmax_t(-1) ); + + const auto bad_ec = ec; + auto link = __gnu_test::nonexistent_path(); + create_symlink(p, link); // dangling symlink + ec = bad_ec; + n = remove_all(link, ec); + VERIFY( !ec ); + VERIFY( n == 1 ); + VERIFY( !exists(symlink_status(link)) ); // DR 2721 + + __gnu_test::scoped_file f(p); + create_symlink(p, link); + ec = bad_ec; + n = remove_all(link, ec); + VERIFY( !ec ); + VERIFY( n == 1 ); + VERIFY( !exists(symlink_status(link)) ); // The symlink is removed, but + VERIFY( exists(p) ); // its target is not. + + auto dir = __gnu_test::nonexistent_path(); + create_directories(dir/"a/b/c"); + ec = bad_ec; + n = remove_all(dir/"a", ec); + VERIFY( !ec ); + VERIFY( n == 3 ); + VERIFY( exists(dir) ); + VERIFY( !exists(dir/"a") ); + + create_directories(dir/"a/b/c"); + __gnu_test::scoped_file a1(dir/"a/1"); + __gnu_test::scoped_file a2(dir/"a/2"); + __gnu_test::scoped_file b1(dir/"a/b/1"); + __gnu_test::scoped_file b2(dir/"a/b/2"); + ec = bad_ec; + n = remove_all(dir, ec); + VERIFY( !ec ); + VERIFY( n == 8 ); + VERIFY( !exists(dir) ); + + a1.path.clear(); + a2.path.clear(); + b1.path.clear(); + b2.path.clear(); +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/operations/space.cc b/libstdc++-v3/testsuite/27_io/filesystem/operations/space.cc new file mode 100644 index 00000000000..7b611352967 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/operations/space.cc @@ -0,0 +1,46 @@ +// Copyright (C) 2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// 30.10.14.3 Permissions [fs.op.space] + +#include <filesystem> +#include <testsuite_fs.h> +#include <testsuite_hooks.h> + +void +test01() +{ + std::filesystem::space_info s = std::filesystem::space("/"); + std::error_code ec = make_error_code(std::errc::invalid_argument); + s = std::filesystem::space("/", ec); + VERIFY( !ec ); + s = std::filesystem::space(__gnu_test::nonexistent_path(), ec); + VERIFY( ec ); + VERIFY( s.capacity == static_cast<uintmax_t>(-1) ); + VERIFY( s.free == static_cast<uintmax_t>(-1) ); + VERIFY( s.available == static_cast<uintmax_t>(-1) ); +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/operations/status.cc b/libstdc++-v3/testsuite/27_io/filesystem/operations/status.cc new file mode 100644 index 00000000000..efe92b26a78 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/operations/status.cc @@ -0,0 +1,97 @@ +// Copyright (C) 2015-2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +#include <filesystem> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +namespace fs = std::filesystem; + +void +test01() +{ + std::error_code ec = make_error_code(std::errc::invalid_argument); + fs::path dot = "."; + + fs::file_status st1 = fs::status(dot, ec); + VERIFY( !ec ); + VERIFY( st1.type() == fs::file_type::directory ); + + fs::file_status st2 = fs::status(dot); + VERIFY( st2.type() == fs::file_type::directory ); +} + +void +test02() +{ + fs::path p = __gnu_test::nonexistent_path(); + + std::error_code ec; + fs::file_status st1 = fs::status(p, ec); + VERIFY( ec ); + VERIFY( st1.type() == fs::file_type::not_found ); + + fs::file_status st2 = fs::status(p); + VERIFY( st2.type() == fs::file_type::not_found ); +} + +void +test03() +{ + fs::path dir = __gnu_test::nonexistent_path(); + fs::create_directory(dir); + __gnu_test::scoped_file d(dir, __gnu_test::scoped_file::adopt_file); + __gnu_test::scoped_file f(dir / "file"); + fs::permissions(dir, fs::perms::none); + + std::error_code ec; + fs::file_status st = fs::status(f.path, ec); + VERIFY( ec.value() == (int)std::errc::permission_denied ); + VERIFY( st.type() == fs::file_type::none ); + +#if __cpp_exceptions + bool caught = false; + std::error_code ec2; + fs::path p, p2; + try { + fs::symlink_status(f.path); + } catch (const fs::filesystem_error& e) { + caught = true; + p = e.path1(); + p2 = e.path2(); + ec2 = e.code(); + } + VERIFY( caught ); + VERIFY( ec2 == ec ); + VERIFY( p == f.path ); + VERIFY( p2.empty() ); +#endif + + fs::permissions(dir, fs::perms::owner_all, ec); +} + +int +main() +{ + test01(); + test02(); + test03(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/operations/symlink_status.cc b/libstdc++-v3/testsuite/27_io/filesystem/operations/symlink_status.cc new file mode 100644 index 00000000000..ae7a76be7c3 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/operations/symlink_status.cc @@ -0,0 +1,118 @@ +// Copyright (C) 2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +#include <filesystem> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +namespace fs = std::filesystem; + +void +test01() +{ + const std::error_code bad_ec = make_error_code(std::errc::invalid_argument); + std::error_code ec = bad_ec; + fs::path dot = "."; + + fs::file_status st1 = fs::symlink_status(dot, ec); + VERIFY( !ec ); + VERIFY( st1.type() == fs::file_type::directory ); + + fs::file_status st2 = fs::symlink_status(dot); + VERIFY( st2.type() == fs::file_type::directory ); + + fs::path link = __gnu_test::nonexistent_path(); + create_directory_symlink(dot, link); + + st1 = fs::symlink_status(link); + VERIFY( st1.type() == fs::file_type::symlink ); + ec = bad_ec; + st2 = fs::symlink_status(link, ec); + VERIFY( !ec ); + VERIFY( st2.type() == fs::file_type::symlink ); +} + +void +test02() +{ + fs::path p = __gnu_test::nonexistent_path(); + + std::error_code ec; + fs::file_status st1 = fs::symlink_status(p, ec); + VERIFY( ec ); + VERIFY( st1.type() == fs::file_type::not_found ); + + fs::file_status st2 = fs::symlink_status(p); + VERIFY( st2.type() == fs::file_type::not_found ); +} + +void +test03() +{ + fs::path dir = __gnu_test::nonexistent_path(); + fs::create_directory(dir); + __gnu_test::scoped_file d(dir, __gnu_test::scoped_file::adopt_file); + __gnu_test::scoped_file f(dir / "file"); + fs::permissions(dir, fs::perms::none); + auto link = __gnu_test::nonexistent_path(); + fs::create_symlink(f.path, link); + __gnu_test::scoped_file l(link, __gnu_test::scoped_file::adopt_file); + + std::error_code ec; + fs::file_status st = fs::symlink_status(f.path, ec); + VERIFY( ec.value() == (int)std::errc::permission_denied ); + VERIFY( st.type() == fs::file_type::none ); + + st = fs::symlink_status(link, ec); + VERIFY( !ec ); + VERIFY( st.type() == fs::file_type::symlink ); + +#if __cpp_exceptions + bool caught = false; + std::error_code ec2; + fs::path p, p2; + try { + fs::symlink_status(f.path); + } catch (const fs::filesystem_error& e) { + caught = true; + p = e.path1(); + p2 = e.path2(); + ec2 = e.code(); + } + VERIFY( caught ); + VERIFY( ec2.value() == (int)std::errc::permission_denied ); + VERIFY( p == f.path ); + VERIFY( p2.empty() ); +#endif + + fs::file_status st2 = symlink_status(link); + VERIFY( st2.type() == fs::file_type::symlink ); + + fs::permissions(dir, fs::perms::owner_all, ec); +} + +int +main() +{ + test01(); + test02(); + test03(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/operations/temp_directory_path.cc b/libstdc++-v3/testsuite/27_io/filesystem/operations/temp_directory_path.cc new file mode 100644 index 00000000000..ee065f0679f --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/operations/temp_directory_path.cc @@ -0,0 +1,127 @@ +// Copyright (C) 2015-2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +#include <filesystem> +#include <stdlib.h> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +void +clean_env() +{ + ::unsetenv("TMPDIR"); + ::unsetenv("TMP"); + ::unsetenv("TEMPDIR"); + ::unsetenv("TEMP"); +} + +namespace fs = std::filesystem; + +void +test01() +{ + clean_env(); + + if (!fs::exists("/tmp")) + return; // just give up + + std::error_code ec = make_error_code(std::errc::invalid_argument); + fs::path p1 = fs::temp_directory_path(ec); + VERIFY( !ec ); + VERIFY( exists(p1) ); + + fs::path p2 = fs::temp_directory_path(); + VERIFY( p1 == p2 ); +} + +void +test02() +{ + clean_env(); + + if (::setenv("TMPDIR", __gnu_test::nonexistent_path().string().c_str(), 1)) + return; // just give up + + std::error_code ec; + fs::path p = fs::temp_directory_path(ec); + VERIFY( ec ); + VERIFY( p == fs::path() ); + + std::error_code ec2; + try { + p = fs::temp_directory_path(); + } catch (const fs::filesystem_error& e) { + ec2 = e.code(); + } + VERIFY( ec2 == ec ); +} + +void +test03() +{ + auto p = __gnu_test::nonexistent_path(); + create_directories(p/"tmp"); + permissions(p, fs::perms::none); + setenv("TMPDIR", (p/"tmp").c_str(), 1); + std::error_code ec; + auto r = fs::temp_directory_path(ec); // libstdc++/PR71337 + VERIFY( ec == std::make_error_code(std::errc::permission_denied) ); + VERIFY( r == fs::path() ); + + std::error_code ec2; + try { + fs::temp_directory_path(); + } catch (const fs::filesystem_error& e) { + ec2 = e.code(); + } + VERIFY( ec2 == ec ); + + permissions(p, fs::perms::owner_all, ec); + remove_all(p, ec); +} + +void +test04() +{ + __gnu_test::scoped_file f; + setenv("TMPDIR", f.path.c_str(), 1); + std::error_code ec; + auto r = fs::temp_directory_path(ec); + VERIFY( ec == std::make_error_code(std::errc::not_a_directory) ); + VERIFY( r == fs::path() ); + + std::error_code ec2; + try { + fs::temp_directory_path(); + } catch (const fs::filesystem_error& e) { + ec2 = e.code(); + } + VERIFY( ec2 == ec ); +} + +int +main() +{ + test01(); + test02(); + test03(); + test04(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/operations/weakly_canonical.cc b/libstdc++-v3/testsuite/27_io/filesystem/operations/weakly_canonical.cc new file mode 100644 index 00000000000..0f285e2bb59 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/operations/weakly_canonical.cc @@ -0,0 +1,70 @@ +// Copyright (C) 2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +#include <filesystem> +#include <testsuite_fs.h> +#include <testsuite_hooks.h> + +namespace fs = std::filesystem; + +void +test01() +{ + auto dir = __gnu_test::nonexistent_path(); + fs::create_directory(dir); + const auto dirc = canonical(dir); + fs::path foo = dir/"foo", bar = dir/"bar"; + fs::create_directory(foo); + fs::create_directory(bar); + fs::create_directory(bar/"baz"); + fs::create_symlink("../bar", foo/"bar"); + + auto p = fs::weakly_canonical(dir/"foo//./bar///../biz/."); + VERIFY( p == dirc/"biz/" ); + p = fs::weakly_canonical(dir/"foo/.//bar/././baz/."); + VERIFY( p == dirc/"bar/baz" ); + p = fs::weakly_canonical(fs::current_path()/dir/"bar//../foo/bar/baz"); + VERIFY( p == dirc/"bar/baz" ); + + const std::error_code bad_ec = make_error_code(std::errc::invalid_argument); + std::error_code ec; + + ec = bad_ec; + p = fs::weakly_canonical(dir/"foo//./bar///../biz/.", ec); + VERIFY( !ec ); + VERIFY( p == dirc/"biz/" ); + ec = bad_ec; + p = fs::weakly_canonical(dir/"foo/.//bar/././baz/.", ec); + VERIFY( !ec ); + VERIFY( p == dirc/"bar/baz" ); + ec = bad_ec; + p = fs::weakly_canonical(fs::current_path()/dir/"bar//../foo/bar/baz", ec); + VERIFY( !ec ); + VERIFY( p == dirc/"bar/baz" ); + + fs::remove_all(dir, ec); +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/append/path.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/append/path.cc new file mode 100644 index 00000000000..0942d6fdf7e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/append/path.cc @@ -0,0 +1,88 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 30.10.7.4.3 path appends [fs.path.append] + +#include <filesystem> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +using std::filesystem::path; +using __gnu_test::compare_paths; + +void +test01() +{ + const path p("/foo/bar"); + + path pp = p; + pp /= p; + compare_paths( pp, p ); + + path q("baz"); + + path qq = q; + qq /= q; + compare_paths( qq, "baz/baz" ); + + q /= p; + compare_paths( q, p ); + + path r = ""; + r /= path(); + VERIFY( r.empty() ); + + r /= path("rel"); + VERIFY( !r.is_absolute() ); + + path s = "dir/"; + s /= path("/file"); + compare_paths( s, "/file" ); + + s = "dir/"; + s /= path("file"); + compare_paths( s, "dir/file" ); +} + +void +test02() +{ + // C++17 [fs.path.append] p4 + + path p = path("//host") / "foo"; + compare_paths( p, "//host/foo" ); + + path pp = path("//host/") / "foo"; + compare_paths( pp, "//host/foo" ); + + path q = path("foo") / ""; + compare_paths( q, "foo/" ); + + path qq = path("foo") / "/bar"; + compare_paths( qq, "/bar" ); +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/assign/assign.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/assign/assign.cc new file mode 100644 index 00000000000..d8797cae168 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/assign/assign.cc @@ -0,0 +1,94 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <testsuite_fs.h> + +using std::filesystem::path; +using __gnu_test::compare_paths; + +void +test01() +{ + for (std::string s : __gnu_test::test_paths) + { + path p0 = s, p1, p2, p3, p4; + + p1 = s; + compare_paths(p0, p1); + + p2 = s.c_str(); + compare_paths(p0, p2); + +#if _GLIBCXX_USE_WCHAR_T + std::wstring ws(s.begin(), s.end()); + + p3 = ws; + compare_paths(p0, p3); + + p4 = ws.c_str(); + compare_paths(p0, p4); +#endif + } +} + +void +test02() +{ + for (std::string s : __gnu_test::test_paths) + { + path p0 = s, p1, p2, p3, p4, p5, p6, p7, p8; + + p1.assign(s); + compare_paths(p0, p1); + + p2.assign( s.begin(), s.end() ); + compare_paths(p0, p2); + + p3.assign( s.c_str() ); + compare_paths(p0, p3); + + p4.assign( s.c_str(), s.c_str() + s.size() ); + compare_paths(p0, p4); + +#if _GLIBCXX_USE_WCHAR_T + std::wstring ws(s.begin(), s.end()); + + p5.assign(ws); + compare_paths(p0, p5); + + p6.assign( ws.begin(), ws.end() ); + compare_paths(p0, p6); + + p7.assign( ws.c_str() ); + compare_paths(p0, p7); + + p8.assign( ws.c_str(), ws.c_str() + ws.size() ); + compare_paths(p0, p8); +#endif + } +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/assign/copy.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/assign/copy.cc new file mode 100644 index 00000000000..27bf00ab126 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/assign/copy.cc @@ -0,0 +1,56 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <filesystem> +#include <testsuite_fs.h> + +using std::filesystem::path; +using __gnu_test::compare_paths; + +void +test01() +{ + for (const path& p : __gnu_test::test_paths) + { + path copy; + copy = p; + __gnu_test::compare_paths(p, copy); + } +} + +void +test02() +{ + for (const path& p : __gnu_test::test_paths) + { + path copy = p; + path move; + move = std::move(copy); + __gnu_test::compare_paths(p, move); + } +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/compare/compare.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/compare/compare.cc new file mode 100644 index 00000000000..e444220ec25 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/compare/compare.cc @@ -0,0 +1,51 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 8.4.8 path compare [path.compare] + +#include <filesystem> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +using std::filesystem::path; + +void +test01() +{ + path p("/foo/bar"); + VERIFY( p.compare(p) == 0 ); + VERIFY( p.compare("/foo//bar") == 0 ); + + path q("/foo/baz"); + VERIFY( p.compare(q) < 0 ); + VERIFY( q.compare(p) > 0 ); + + path r("/foo/bar/."); + VERIFY( p.compare(r) < 0 ); + + VERIFY( path("a/b/").compare("a/b//") == 0 ); +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/compare/path.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/compare/path.cc new file mode 100644 index 00000000000..4bed5a23fd5 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/compare/path.cc @@ -0,0 +1,51 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 8.4.8 path compare [path.compare] + +#include <filesystem> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +using std::filesystem::path; + +void +test01() +{ + const path p0 = "/a/a/b/b"; + for (const path& p : __gnu_test::test_paths) + { + VERIFY( p.compare(p) == 0 ); + int cmp = p.compare(p0); + if (cmp == 0) + VERIFY( p0.compare(p) == 0 ); + else if (cmp < 0) + VERIFY( p0.compare(p) > 0 ); + else if (cmp > 0) + VERIFY( p0.compare(p) < 0 ); + } +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/compare/strings.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/compare/strings.cc new file mode 100644 index 00000000000..be8f8b0d709 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/compare/strings.cc @@ -0,0 +1,49 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 8.4.8 path compare [path.compare] + +#include <filesystem> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +using std::filesystem::path; + +void +test01() +{ + const std::string s0 = "/a/a/b/b"; + const path p0 = s0; + for (const std::string& s : __gnu_test::test_paths) + { + path p(s); + VERIFY( p.compare(s) == 0 ); + VERIFY( p.compare(s.c_str()) == 0 ); + VERIFY( p.compare(p0) == p.compare(s0) ); + VERIFY( p.compare(p0) == p.compare(s0.c_str()) ); + } +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/concat/path.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/concat/path.cc new file mode 100644 index 00000000000..1a987c1966b --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/concat/path.cc @@ -0,0 +1,67 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 30.10.7.4.4 path concatenation [fs.path.concat] + +#include <filesystem> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +using std::filesystem::path; +using __gnu_test::compare_paths; + +void +test01() +{ + const path p("/foo/bar"); + + path pp = p; + pp += p; + compare_paths( pp, "/foo/bar/foo/bar" ); + + path q("foo/bar"); + + path qq = q; + qq += q; + compare_paths( qq, "foo/barfoo/bar" ); + + q += p; + compare_paths( q, "foo/bar/foo/bar" ); +} + +void +test02() +{ + for (path p : __gnu_test::test_paths) + { + auto prior_native = p.native(); + path x("//blah/di/blah"); + p += x; + VERIFY( p.native() == prior_native + x.native() ); + } +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/concat/strings.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/concat/strings.cc new file mode 100644 index 00000000000..8d298f8a57d --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/concat/strings.cc @@ -0,0 +1,56 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 30.10.7.4.4 path concatenation [fs.path.concat] + +#include <filesystem> +#include <testsuite_hooks.h> + +using std::filesystem::path; + +void +test01() +{ + path p("/"); + p += path::string_type("foo"); + VERIFY( p.filename() == "foo" ); + p += "bar"; + VERIFY( p.filename() == "foobar" ); + p += '/'; + VERIFY( p.parent_path() == "/foobar" && p.filename() == "" ); +#if _GLIBCXX_USE_WCHAR_T + p += L"baz.txt"; +#else + p += "baz.txt"; +#endif + VERIFY( p.filename() == "baz.txt" ); + p.concat("/dir/"); + VERIFY( p.parent_path() == "/foobar/baz.txt/dir" && p.filename() == "" ); + std::string file = "file"; + p.concat(file.begin(), file.end()); + VERIFY( p.filename() == "file" ); +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/construct/copy.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/construct/copy.cc new file mode 100644 index 00000000000..cb084bdfeda --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/construct/copy.cc @@ -0,0 +1,55 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 8.4.1 path constructors [path.construct] + +#include <filesystem> +#include <testsuite_fs.h> + +using std::filesystem::path; + +void +test01() +{ + for (const path& p : __gnu_test::test_paths) + { + path copy = p; + __gnu_test::compare_paths(p, copy); + } +} + +void +test02() +{ + for (const path& p : __gnu_test::test_paths) + { + path copy = p; + path move = std::move(copy); + __gnu_test::compare_paths(p, move); + } +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/construct/default.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/construct/default.cc new file mode 100644 index 00000000000..85ce129436d --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/construct/default.cc @@ -0,0 +1,51 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 8.4.1 path constructors [path.construct] + +#include <filesystem> +#include <testsuite_hooks.h> + +using std::filesystem::path; + +void +test01() +{ + path p; + VERIFY( p.empty() ); + VERIFY( !p.has_root_path() ); + VERIFY( !p.has_root_name() ); + VERIFY( !p.has_root_directory() ); + VERIFY( !p.has_relative_path() ); + VERIFY( !p.has_parent_path() ); + VERIFY( !p.has_filename() ); + VERIFY( !p.has_stem() ); + VERIFY( !p.has_extension() ); + VERIFY( !p.is_absolute() ); + VERIFY( p.is_relative() ); + VERIFY( std::distance(p.begin(), p.end()) == 0 ); +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/construct/format.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/construct/format.cc new file mode 100644 index 00000000000..e7ed19cafe9 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/construct/format.cc @@ -0,0 +1,116 @@ +// Copyright (C) 2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +#include <filesystem> +#include <testsuite_hooks.h> + +using std::filesystem::path; + +void +test01() +{ + auto s = [&]() -> path::string_type { return "foo/bar"; }; + path p0(s()); + path p1(s(), path::auto_format); + VERIFY( p1 == p0 ); + path p2(s(), path::native_format); + VERIFY( p2 == p0 ); + path p3(s(), path::generic_format); + VERIFY( p3 == p0 ); +} + +void +test02() +{ + path::string_type s = "foo/bar"; + path p0(s); + path p1(s, path::auto_format); + VERIFY( p1 == p0 ); + path p2(s, path::native_format); + VERIFY( p2 == p0 ); + path p3(s, path::generic_format); + VERIFY( p3 == p0 ); +} + +void +test03() +{ + const char* s = "foo/bar"; + path p0(s); + path p1(s, path::auto_format); + VERIFY( p1 == p0 ); + path p2(s, path::native_format); + VERIFY( p2 == p0 ); + path p3(s, path::generic_format); + VERIFY( p3 == p0 ); +} + +void +test04() +{ + const char s[] = "foo/bar"; + path p0(std::begin(s), std::end(s)); + path p1(std::begin(s), std::end(s), path::auto_format); + VERIFY( p1 == p0 ); + path p2(std::begin(s), std::end(s), path::native_format); + VERIFY( p2 == p0 ); + path p3(std::begin(s), std::end(s), path::generic_format); + VERIFY( p3 == p0 ); +} + +void +test05() +{ + const char* s = "foo/bar"; + std::locale loc; + path p0(s, loc); + path p1(s, loc, path::auto_format); + VERIFY( p1 == p0 ); + path p2(s, loc, path::native_format); + VERIFY( p2 == p0 ); + path p3(s, loc, path::generic_format); + VERIFY( p3 == p0 ); +} + +void +test06() +{ + const char s[] = "foo/bar"; + std::locale loc; + path p0(std::begin(s), std::end(s), loc); + path p1(std::begin(s), std::end(s), loc, path::auto_format); + VERIFY( p1 == p0 ); + path p2(std::begin(s), std::end(s), loc, path::native_format); + VERIFY( p2 == p0 ); + path p3(std::begin(s), std::end(s), loc, path::generic_format); + VERIFY( p3 == p0 ); +} + +int +main() +{ + test01(); + test02(); + test03(); + test04(); + test05(); + test06(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/construct/locale.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/construct/locale.cc new file mode 100644 index 00000000000..8bbff810652 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/construct/locale.cc @@ -0,0 +1,40 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 30.10.7.4.1 path constructors [fs.path.construct] + +#include <filesystem> +#include <testsuite_hooks.h> + +using std::filesystem::path; + +void +test01() +{ + path p("/foo/bar", std::locale::classic()); + VERIFY( p.native() == "/foo/bar" ); +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/construct/range.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/construct/range.cc new file mode 100644 index 00000000000..ad2cc18e512 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/construct/range.cc @@ -0,0 +1,112 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 8.4.1 path constructors [path.construct] + +#include <filesystem> +#include <string> +#include <testsuite_fs.h> +#include <testsuite_iterators.h> + +using std::filesystem::path; +using __gnu_test::compare_paths; + +void +test01() +{ + for (std::string s : __gnu_test::test_paths) + { + path p1 = s; + path p2( s.begin(), s.end() ); + path p3( s.c_str() ); + path p4( s.c_str(), s.c_str() + s.size() ); + + compare_paths(p1, p2); + compare_paths(p1, p3); + compare_paths(p1, p4); + +#if _GLIBCXX_USE_WCHAR_T + std::wstring ws(s.begin(), s.end()); + path p5 = ws; + path p6( ws.begin(), ws.end() ); + path p7( ws.c_str() ); + path p8( ws.c_str(), ws.c_str() + ws.size() ); + + compare_paths(p1, p5); + compare_paths(p1, p6); + compare_paths(p1, p7); + compare_paths(p1, p8); +#endif + + using __gnu_test::test_container; + using __gnu_test::input_iterator_wrapper; + // Test with input iterators and const value_types + + test_container<char, input_iterator_wrapper> + r1((char*)s.c_str(), (char*)s.c_str() + s.size()); + path p9(r1.begin(), r1.end()); + compare_paths(p1, p9); + + test_container<char, input_iterator_wrapper> + r2((char*)s.c_str(), (char*)s.c_str() + s.size() + 1); // includes null-terminator + path p10(r2.begin()); + compare_paths(p1, p10); + + test_container<const char, input_iterator_wrapper> + r3(s.c_str(), s.c_str() + s.size()); + path p11(r3.begin(), r3.end()); + compare_paths(p1, p11); + + test_container<const char, input_iterator_wrapper> + r4(s.c_str(), s.c_str() + s.size() + 1); // includes null-terminator + path p12(r4.begin()); + compare_paths(p1, p12); + +#if _GLIBCXX_USE_WCHAR_T + // Test with input iterators and const value_types + test_container<wchar_t, input_iterator_wrapper> + r5((wchar_t*)ws.c_str(), (wchar_t*)ws.c_str() + ws.size()); + path p13(r5.begin(), r5.end()); + compare_paths(p1, p13); + + test_container<wchar_t, input_iterator_wrapper> + r6((wchar_t*)ws.c_str(), (wchar_t*)ws.c_str() + ws.size() + 1); // includes null-terminator + path p14(r6.begin()); + compare_paths(p1, p14); + + test_container<const wchar_t, input_iterator_wrapper> + r7(ws.c_str(), ws.c_str() + ws.size()); + path p15(r7.begin(), r7.end()); + compare_paths(p1, p15); + + test_container<const wchar_t, input_iterator_wrapper> + r8(ws.c_str(), ws.c_str() + ws.size() + 1); // includes null-terminator + path p16(r8.begin()); + compare_paths(p1, p16); +#endif + } +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/construct/string_view.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/construct/string_view.cc new file mode 100644 index 00000000000..b9a52058791 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/construct/string_view.cc @@ -0,0 +1,56 @@ +// { dg-options "-lstdc++fs -std=gnu++17" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2016-2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 8.4.1 path constructors [path.construct] + +#include <filesystem> +#include <string_view> +#include <string> +#include <testsuite_fs.h> + +using std::filesystem::path; +using __gnu_test::compare_paths; + +void +test01() +{ + for (std::string s : __gnu_test::test_paths) + { + path p1 = s; + std::string_view sv(s); + path p2 = sv; + compare_paths(p1, p2); + +#if _GLIBCXX_USE_WCHAR_T + std::wstring ws(s.begin(), s.end()); + path p3 = ws; + std::wstring_view wsv(ws); + path p4 = wsv; + compare_paths(p1, p4); +#endif + } +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/extension.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/extension.cc new file mode 100644 index 00000000000..13c9db275a0 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/extension.cc @@ -0,0 +1,70 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 8.4.9 path decomposition [path.decompose] + +#include <filesystem> +#include <vector> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +using std::filesystem::path; + +void +test01() +{ + VERIFY( path("/foo/bar.txt").extension() == path(".txt") ); + VERIFY( path("/foo/bar.baz.txt").extension() == path(".txt") ); + VERIFY( path(".bar.baz.txt").extension() == path(".txt") ); + + VERIFY( path(".profile").extension() == path("") ); + VERIFY( path(".profile.old").extension() == path(".old") ); + VERIFY( path("..abc").extension() == path(".abc") ); + VERIFY( path("...abc").extension() == path(".abc") ); + VERIFY( path("abc..def").extension() == path(".def") ); + VERIFY( path("abc...def").extension() == path(".def") ); + VERIFY( path("abc.").extension() == path(".") ); + VERIFY( path("abc..").extension() == path(".") ); + VERIFY( path("abc.d.").extension() == path(".") ); + VERIFY( path("..").extension() == path("") ); + VERIFY( path(".").extension() == path("") ); + + VERIFY( path().extension() == path() ); +} + +void +test02() +{ + for (const path& p : __gnu_test::test_paths) + { + auto stem = p.stem(); + auto ext = p.extension(); + auto file = p.filename(); + VERIFY( stem.native() + ext.native() == file.native() ); + } +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/filename.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/filename.cc new file mode 100644 index 00000000000..8ba0fcc8cb9 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/filename.cc @@ -0,0 +1,70 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// C++17 30.10.7.4.9 path decomposition [fs.path.decompose] + +#include <filesystem> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +using std::filesystem::path; + +void +test01() +{ + VERIFY( path("/foo/bar.txt").filename() == "bar.txt" ); + VERIFY( path("/foo/bar").filename() == "bar" ); + VERIFY( path("/foo/bar/").filename() == "" ); + VERIFY( path("/").filename() == "" ); +#ifdef __CYGWIN__ + VERIFY( path("//host").filename() == "" ); +#else + VERIFY( path("//host").filename() == "host" ); +#endif + VERIFY( path(".").filename() == "." ); + VERIFY( path("..").filename() == ".." ); +} + +void +test02() +{ + for (const path& p : __gnu_test::test_paths) + { + path f = p.filename(); + if (p.empty()) + VERIFY( f.empty() ); + else + { + const path back = *--p.end(); + if (back.has_root_path()) + VERIFY( f.empty() ); + else + VERIFY( f == back ); + } + } +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/parent_path.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/parent_path.cc new file mode 100644 index 00000000000..c46566dad40 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/parent_path.cc @@ -0,0 +1,73 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 8.4.9 path decomposition [path.decompose] + +#include <filesystem> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +using std::filesystem::path; + +void +test01() +{ + path p0; + VERIFY( p0.parent_path() == p0 ); + path p1 = "foo"; + VERIFY( p1.parent_path() == p0 ); + path p2 = "foo/bar"; + VERIFY( p2.parent_path() == p1 ); + path p3 = "/foo/bar"; + VERIFY( p3.parent_path() == path("/foo") ); + VERIFY( p3.parent_path().parent_path() == path("/") ); + VERIFY( p3.parent_path().parent_path().parent_path() == path("/") ); + path p4 = "/"; + VERIFY( p4.parent_path() == p4 ); +} + +void +test02() +{ + for (const path& p : __gnu_test::test_paths) + { + if (p.begin() == p.end()) + continue; + if (p.has_relative_path()) + { + path pp; + for (auto i = p.begin(), end = --p.end(); i != end; ++i) + { + pp /= *i; + } + VERIFY( p.parent_path() == pp ); + } + else + VERIFY( p.parent_path() == p ); + } +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/relative_path.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/relative_path.cc new file mode 100644 index 00000000000..c8649724671 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/relative_path.cc @@ -0,0 +1,70 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 8.4.9 path decomposition [path.decompose] + +#include <filesystem> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +using std::filesystem::path; + +void +test01() +{ + path p1 = "foo"; + VERIFY( p1.relative_path() == p1 ); + path p2 = "foo/bar"; + VERIFY( p2.relative_path() == p2 ); + path p3 = "/foo/bar"; + VERIFY( p3.relative_path() == p2 ); +} + +#include <iostream> // XXX + +void +test02() +{ + for (const path& p : __gnu_test::test_paths) + { + bool after_root = false; + const path prel = p.relative_path(); + VERIFY( !prel.has_root_name() ); + path rel; + for (const auto& cmpt : p) + { + if (!cmpt.has_root_path()) + after_root = true; + if (after_root) + rel /= cmpt; + } + if (prel != rel) + std::cout << prel << ' ' << rel << '\n'; + VERIFY( prel == rel ); + } +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/root_directory.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/root_directory.cc new file mode 100644 index 00000000000..8cd1976a946 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/root_directory.cc @@ -0,0 +1,59 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 30.10.7.4.9 path decomposition [fs.path.decompose] + +#include <filesystem> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +using std::filesystem::path; + +void +test01() +{ + path p1 = "foo/bar"; + VERIFY( p1.root_directory() == path() ); + path p2 = "/foo/bar"; + VERIFY( p2.root_directory() == path("/") ); + path p3 = "//foo"; + VERIFY( p3.root_directory() == path("/") ); + path p4 = "///foo"; + VERIFY( p4.root_directory() == path("/") ); +} + +void +test02() +{ + for (const path& p : __gnu_test::test_paths) + { + path rootdir = p.root_directory(); + VERIFY( !rootdir.has_relative_path() ); + VERIFY( rootdir.empty() || rootdir.native() == "/"); + } +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/root_name.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/root_name.cc new file mode 100644 index 00000000000..5bb2ccd177e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/root_name.cc @@ -0,0 +1,43 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 8.4.9 path decomposition [path.decompose] + +#include <filesystem> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +using std::filesystem::path; + +void +test01() +{ + VERIFY( path("/foo/bar.txt").extension() == ".txt" ); + VERIFY( path("/foo/bar.baz.txt").extension() == ".txt" ); + VERIFY( path(".").extension().empty() ); + VERIFY( path("..").extension().empty() ); +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/root_path.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/root_path.cc new file mode 100644 index 00000000000..bce0134a447 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/root_path.cc @@ -0,0 +1,61 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// C++17 30.10.7.4.9 path decomposition [fs.path.decompose] + +#include <filesystem> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +using std::filesystem::path; + +void +test01() +{ + path p1 = "foo/bar"; + VERIFY( p1.root_path() == path() ); + path p2 = "/foo/bar"; + VERIFY( p2.root_path() == path("/") ); +} + +#undef VERIFY +#define VERIFY(X) do { if (!(X)) { __builtin_puts("FAIL: " #X); } } while(false) +#define DUMP(X, Y, Z) do { if (!(Y == Z)) { __builtin_printf("%s %s %s\n", X.c_str(), Y.c_str(), Z.c_str()); } } while(false) + +void +test02() +{ + for (const path& p : __gnu_test::test_paths) + { + path rootp = p.root_path(); + path rootn = p.root_name(); + path rootd = p.root_directory(); + VERIFY( rootp == (rootn / rootd) ); + DUMP(p, rootp , (rootn / rootd) ); + } +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/stem.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/stem.cc new file mode 100644 index 00000000000..aec64e172ff --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/stem.cc @@ -0,0 +1,62 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 8.4.9 path decomposition [path.decompose] + +#include <filesystem> +#include <vector> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +using std::filesystem::path; + +void +test01() +{ + VERIFY( path("/foo/bar.txt").stem() == path("bar") ); + path p = "foo.bar.baz.tar"; + std::vector<std::string> v; + for (; !p.extension().empty(); p = p.stem()) + v.push_back(p.extension().native()); + VERIFY( v.at(0) == ".tar" ); + VERIFY( v.at(1) == ".baz" ); + VERIFY( v.at(2) == ".bar" ); + + VERIFY( path(".profile").stem() == path(".profile") ); + VERIFY( path(".profile.old").stem() == path(".profile") ); + VERIFY( path("..abc").stem() == path(".") ); + VERIFY( path("...abc").stem() == path("..") ); + VERIFY( path("abc..def").stem() == path("abc.") ); + VERIFY( path("abc...def").stem() == path("abc..") ); + VERIFY( path("abc.").stem() == path("abc") ); + VERIFY( path("abc..").stem() == path("abc.") ); + VERIFY( path("abc.d.").stem() == path("abc.d") ); + VERIFY( path("..").stem() == path("..") ); + VERIFY( path(".").stem() == path(".") ); + + VERIFY( path().stem() == path() ); +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/generation/normal.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/generation/normal.cc new file mode 100644 index 00000000000..df3b7154ab3 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/generation/normal.cc @@ -0,0 +1,128 @@ +// Copyright (C) 2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +#include <filesystem> +#include <testsuite_fs.h> +#include <testsuite_hooks.h> + +using std::filesystem::path; +using __gnu_test::compare_paths; + +void +test01() +{ + // C++17 [fs.path.gen] p2 + compare_paths( path("foo/./bar/..").lexically_normal(), "foo/" ); + compare_paths( path("foo/.///bar/../").lexically_normal(), "foo/" ); +} + +void +test02() +{ + compare_paths( path("foo/../bar").lexically_normal(), "bar" ); + compare_paths( path("../foo/../bar").lexically_normal(), "../bar" ); + compare_paths( path("foo/../").lexically_normal(), "." ); + compare_paths( path("../../").lexically_normal(), "../.." ); + compare_paths( path("../").lexically_normal(), ".." ); + compare_paths( path("./").lexically_normal(), "." ); + compare_paths( path().lexically_normal(), "" ); + + compare_paths( path("/..").lexically_normal(), "/" ); + + // PR libstdc++/82777 + compare_paths( path("./a/b/c/../.././b/c").lexically_normal(), "a/b/c" ); + compare_paths( path("/a/b/c/../.././b/c").lexically_normal(), "/a/b/c" ); +} + +void +test03() +{ + struct + { + const char* input; + const char* normalized; + } testcases[] = { + {"" , "" }, + {"." , "." }, + {".." , ".." }, + {"/" , "/" }, + {"//" , "//" }, + + {"/foo" , "/foo" }, + {"/foo/" , "/foo/" }, + {"/foo/." , "/foo/" }, + {"/foo/bar/.." , "/foo/" }, + {"/foo/.." , "/" }, + + {"/." , "/" }, + {"/./" , "/" }, + {"/./." , "/" }, + {"/././" , "/" }, + {"/././." , "/" }, + + {"./" , "." }, + {"./." , "." }, + {"././" , "." }, + {"././." , "." }, + {"./././" , "." }, + {"./././." , "." }, + + {"foo/.." , "." }, + {"foo/../" , "." }, + {"foo/../.." , ".." }, + + // with root name (OS-dependent): +#if defined(_WIN32) && !defined(__CYGWIN__) + {"C:bar/.." , "C:." }, +#else + {"C:bar/.." , "." }, +#endif + {"C:/bar/.." , "C:/" }, + {"C:" , "C:" }, +#ifdef __CYGWIN__ + {"//host/bar/.." , "//host/" }, + {"//host" , "//host" }, +#else + {"//host/bar/.." , "/host/" }, + {"//host" , "/host" }, +#endif + + // a few others: + {"foo/../foo/.." , "." }, + {"foo/../foo/../.." , ".." }, + {"../foo/../foo/.." , ".." }, + {"../.f/../f" , "../f" }, + {"../f/../.f" , "../.f" }, + {".././../." , "../.." }, + {".././.././" , "../.." }, + {"/.." , "/" }, + }; + for (auto& test : testcases) + compare_paths( path(test.input).lexically_normal(), test.normalized ); +} + +int +main() +{ + test01(); + test02(); + test03(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/generation/proximate.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/generation/proximate.cc new file mode 100644 index 00000000000..ee77e16d1f8 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/generation/proximate.cc @@ -0,0 +1,55 @@ +// Copyright (C) 2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +#include <filesystem> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +using std::filesystem::path; +using __gnu_test::compare_paths; + +void +test01() +{ + // C++17 [fs.path.gen] p5 + compare_paths( path("/a/d").lexically_proximate("/a/b/c"), "../../d" ); + compare_paths( path("/a/b/c").lexically_proximate("/a/d"), "../b/c" ); + compare_paths( path("a/b/c").lexically_proximate("a"), "b/c" ); + compare_paths( path("a/b/c").lexically_proximate("a/b/c/x/y"), "../.." ); + compare_paths( path("a/b/c").lexically_proximate("a/b/c"), "." ); + compare_paths( path("a/b").lexically_proximate("c/d"), "../../a/b" ); +} + +void +test02() +{ + path p = "a/b/c"; + compare_paths( p.lexically_proximate(p), "." ); + compare_paths( p.lexically_proximate("a/../a/b/../b/c/../c/."), "../../b/c" ); + compare_paths( p.lexically_proximate("../../../"), p ); +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/generation/relative.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/generation/relative.cc new file mode 100644 index 00000000000..3e78344a618 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/generation/relative.cc @@ -0,0 +1,55 @@ +// Copyright (C) 2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +#include <filesystem> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +using std::filesystem::path; +using __gnu_test::compare_paths; + +void +test01() +{ + // C++17 [fs.path.gen] p5 + compare_paths( path("/a/d").lexically_relative("/a/b/c"), "../../d" ); + compare_paths( path("/a/b/c").lexically_relative("/a/d"), "../b/c" ); + compare_paths( path("a/b/c").lexically_relative("a"), "b/c" ); + compare_paths( path("a/b/c").lexically_relative("a/b/c/x/y"), "../.." ); + compare_paths( path("a/b/c").lexically_relative("a/b/c"), "." ); + compare_paths( path("a/b").lexically_relative("c/d"), "../../a/b" ); +} + +void +test02() +{ + path p = "a/b/c"; + compare_paths( p.lexically_relative(p), "." ); + compare_paths( p.lexically_relative("a/../a/b/../b/c/../c/."), "../../b/c" ); + compare_paths( p.lexically_relative("../../../"), "" ); +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/generic/generic_string.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/generic/generic_string.cc new file mode 100644 index 00000000000..78224339b42 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/generic/generic_string.cc @@ -0,0 +1,54 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// C++17 30.10.7.4.7 path generic format observers [fs.path.generic.obs] + +#include <filesystem> +#include <testsuite_hooks.h> + +using std::filesystem::path; + +void +test01() +{ + VERIFY( path().generic_string() == "" ); + VERIFY( path("/").generic_string() == "/" ); + VERIFY( path("////").generic_string() == "/" ); +#ifdef __CYGWIN__ + VERIFY( path("//a").generic_string() == "//a" ); + VERIFY( path("//a/").generic_string() == "//a/" ); + VERIFY( path("//a/b").generic_string() == "//a/b" ); +#else + VERIFY( path("//a").generic_string() == "/a" ); + VERIFY( path("//a/").generic_string() == "/a/" ); + VERIFY( path("//a/b").generic_string() == "/a/b" ); +#endif + VERIFY( path("/a//b").generic_string() == "/a/b" ); + VERIFY( path("/a//b/").generic_string() == "/a/b/" ); + VERIFY( path("/a//b//").generic_string() == "/a/b/" ); + VERIFY( path("/a//b//.").generic_string() == "/a/b/." ); +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/itr/traversal.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/itr/traversal.cc new file mode 100644 index 00000000000..7754140a714 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/itr/traversal.cc @@ -0,0 +1,127 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// C++17 30.10.7.5 path iterators [fs.path.itr] + +#include <filesystem> +#include <vector> +#include <algorithm> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +using std::filesystem::path; + +void +test01() +{ + path p; + VERIFY( p.begin() == p.end() ); + + std::vector<path> v, v2; + + p = "/"; + v.assign(p.begin(), p.end()); + v2 = { "/" }; + VERIFY( v == v2 ); + + p = "filename"; + v.assign(p.begin(), p.end()); + v2 = { "filename" }; + VERIFY( v == v2 ); + + p = "dir/."; + v.assign(p.begin(), p.end()); + v2 = { "dir", "." }; + VERIFY( v == v2 ); + + p = "dir/"; + v.assign(p.begin(), p.end()); + v2 = { "dir", "" }; + VERIFY( v == v2 ); + + p = "//rootname/dir/."; + v.assign(p.begin(), p.end()); +#ifdef __CYGWIN__ + v2 = { "//rootname", "/", "dir", "." }; +#else + v2 = { "/", "rootname", "dir", "." }; +#endif + VERIFY( v == v2 ); + + p = "//rootname/dir/"; + v.assign(p.begin(), p.end()); +#ifdef __CYGWIN__ + v2 = { "//rootname", "/", "dir", "" }; +#else + v2 = { "/", "rootname", "dir", "" }; +#endif + VERIFY( v == v2 ); + + p = "//rootname/dir/filename"; + v.assign(p.begin(), p.end()); +#ifdef __CYGWIN__ + v2 = { "//rootname", "/", "dir", "filename" }; +#else + v2 = { "/", "rootname", "dir", "filename" }; +#endif + VERIFY( v == v2 ); +} + +void +test02() +{ + using reverse_iterator = std::reverse_iterator<path::iterator>; + std::vector<path> fwd, rev; + + for (const path& p : __gnu_test::test_paths) + { + const auto begin = p.begin(), end = p.end(); + fwd.assign(begin, end); + rev.assign(reverse_iterator(end), reverse_iterator(begin)); + VERIFY( fwd.size() == rev.size() ); + VERIFY( std::equal(fwd.begin(), fwd.end(), rev.rbegin()) ); + } +} + +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(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/modifiers/clear.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/modifiers/clear.cc new file mode 100644 index 00000000000..31d984f1aa0 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/modifiers/clear.cc @@ -0,0 +1,46 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 8.4.5 path modifiers [path.modifiers] + +#include <filesystem> +#include <testsuite_fs.h> +#include <testsuite_hooks.h> + +using std::filesystem::path; + +void +test01() +{ + for (path p : __gnu_test::test_paths) + { + path empty; + p.clear(); + VERIFY( p.empty() ); + __gnu_test::compare_paths(p, empty); + } +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/modifiers/make_preferred.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/modifiers/make_preferred.cc new file mode 100644 index 00000000000..6e306a41c2b --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/modifiers/make_preferred.cc @@ -0,0 +1,64 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 30.10.7.4.5 path modifiers [fs.path.modifiers] + +#include <filesystem> +#include <testsuite_fs.h> +#include <testsuite_hooks.h> + +using std::filesystem::path; + +template<typename T, T sep> +struct checker +{ + static void check(const char* s) { } +}; + +template<> +struct checker<char, '/'> +{ + static void check() + { + VERIFY( path("foo/bar").make_preferred() == "foo/bar" ); + } +}; + +template<> +struct checker<wchar_t, L'\\'> +{ + static void check() + { + VERIFY( path("foo/bar").make_preferred() == L"foo\\bar" ); + } +}; + +void +test01() +{ + checker<path::value_type, path::preferred_separator>::check(); +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/modifiers/remove_filename.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/modifiers/remove_filename.cc new file mode 100644 index 00000000000..cb764cd1585 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/modifiers/remove_filename.cc @@ -0,0 +1,58 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// C++17 30.10.7.4.5 path modifiers [fs.path.modifiers] + +#include <filesystem> +#include <testsuite_fs.h> +#include <testsuite_hooks.h> + +using std::filesystem::path; +using __gnu_test::compare_paths; + +void +test01() +{ + // C++17 [fs.path.modifiers] p8 + compare_paths( path("foo/bar").remove_filename(), "foo/" ); + compare_paths( path("foo/").remove_filename() , "foo/" ); + compare_paths( path("/foo").remove_filename() , "/" ); + compare_paths( path("/").remove_filename() , "/" ); +} + +void +test02() +{ + for (const path& p : __gnu_test::test_paths) + { + path p2(p); + p2.remove_filename(); + p2 /= p.filename(); + compare_paths( p2, p ); + } +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/modifiers/replace_extension.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/modifiers/replace_extension.cc new file mode 100644 index 00000000000..fca189ce040 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/modifiers/replace_extension.cc @@ -0,0 +1,54 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 30.10.7.4.5 path modifiers [fs.path.modifiers] + +#include <filesystem> +#include <testsuite_fs.h> +#include <testsuite_hooks.h> + +using std::filesystem::path; +using __gnu_test::compare_paths; + +void +test01() +{ + compare_paths( path("/foo.txt").replace_extension("cpp"), "/foo.cpp" ); + compare_paths( path("/foo.txt").replace_extension(".cpp"), "/foo.cpp" ); + compare_paths( path("/").replace_extension("bar"), "/.bar" ); +} + +void +test02() +{ + for (const path& p : __gnu_test::test_paths) + { + path p2 = p; + compare_paths( p2.replace_extension(p2.extension()), p ); + } +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/modifiers/replace_filename.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/modifiers/replace_filename.cc new file mode 100644 index 00000000000..d5c36565aca --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/modifiers/replace_filename.cc @@ -0,0 +1,55 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// C++17 30.10.7.4.5 path modifiers [fs.path.modifiers] + +#include <filesystem> +#include <testsuite_fs.h> +#include <testsuite_hooks.h> + +using std::filesystem::path; +using __gnu_test::compare_paths; + +void +test01() +{ + // C++17 [fs.path.modifiers] p11 + compare_paths( path("/foo").replace_filename("bar"), "/bar" ); + compare_paths( path("/").replace_filename("bar") , "/bar" ); +} + +void +test02() +{ + for (const path& p : __gnu_test::test_paths) + { + path p2(p); + p2.replace_filename(p.filename()); + compare_paths( p2, p ); + } +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/modifiers/swap.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/modifiers/swap.cc new file mode 100644 index 00000000000..f1276042a95 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/modifiers/swap.cc @@ -0,0 +1,45 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 8.4.5 path modifiers [path.modifiers] + +#include <filesystem> +#include <testsuite_fs.h> +#include <testsuite_hooks.h> + +using std::filesystem::path; + +void +test01() +{ + const path p("/foo/bar"); + path p1; + path p2 = p; + p1.swap(p2); + VERIFY( p2.empty() ); + __gnu_test::compare_paths(p1, p); +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/native/string.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/native/string.cc new file mode 100644 index 00000000000..23d79700d97 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/native/string.cc @@ -0,0 +1,70 @@ +// Copyright (C) 2016-2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +#include <filesystem> +#include <string> +#include <testsuite_hooks.h> + +void +test01() +{ + using namespace std::filesystem; + const std::string s = "abc"; + path p(s); + + VERIFY( p.native() == s ); + VERIFY( p.c_str() == s ); + VERIFY( static_cast<std::string>(p) == s ); + + std::string s2 = p; // implicit conversion + VERIFY( s2 == p.native() ); +} + +void +test02() +{ + using namespace std::filesystem; + const char* s = "abc"; + path p(s); + + auto str = p.string<char>(); + VERIFY( str == u"abc" ); + VERIFY( str == p.string() ); + + auto strw = p.string<wchar_t>(); + VERIFY( strw == L"abc" ); + VERIFY( strw == p.wstring() ); + + auto str16 = p.string<char16_t>(); + VERIFY( str16 == u"abc" ); + VERIFY( str16 == p.u16string() ); + + auto str32 = p.string<char32_t>(); + VERIFY( str32 == U"abc" ); + VERIFY( str32 == p.u32string() ); +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/nonmember/hash_value.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/nonmember/hash_value.cc new file mode 100644 index 00000000000..20f42ac6ee5 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/nonmember/hash_value.cc @@ -0,0 +1,52 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 8.6 path non-member functions [path.non-member] + +#include <filesystem> +#include <testsuite_fs.h> +#include <testsuite_hooks.h> + +using std::filesystem::path; + +void +test01() +{ + VERIFY( hash_value(path("a//b")) == hash_value(path("a/b")) ); + VERIFY( hash_value(path("a/")) == hash_value(path("a//")) ); +} + +void +test02() +{ + for (const path& p : __gnu_test::test_paths) + { + path pp = p.native(); + VERIFY( hash_value(p) == hash_value(pp) ); + } +} + +int +main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/query/empty.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/query/empty.cc new file mode 100644 index 00000000000..76277a0c9ff --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/query/empty.cc @@ -0,0 +1,44 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 8.4.9 path decomposition [path.decompose] + +#include <filesystem> +#include <vector> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +using std::filesystem::path; + +void +test01() +{ + for (const std::string& s : __gnu_test::test_paths) + { + VERIFY( s.empty() == path(s).empty() ); + } +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/query/has_extension.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/query/has_extension.cc new file mode 100644 index 00000000000..693bd389dcd --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/query/has_extension.cc @@ -0,0 +1,44 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 8.4.9 path decomposition [path.decompose] + +#include <filesystem> +#include <vector> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +using std::filesystem::path; + +void +test01() +{ + for (const path& p : __gnu_test::test_paths) + { + VERIFY( p.has_extension() == !p.extension().empty() ); + } +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/query/has_filename.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/query/has_filename.cc new file mode 100644 index 00000000000..ce99af3025f --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/query/has_filename.cc @@ -0,0 +1,44 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 8.4.9 path decomposition [path.decompose] + +#include <filesystem> +#include <vector> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +using std::filesystem::path; + +void +test01() +{ + for (const path& p : __gnu_test::test_paths) + { + VERIFY( p.has_filename() == !p.filename().empty() ); + } +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/query/has_parent_path.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/query/has_parent_path.cc new file mode 100644 index 00000000000..4e23b249607 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/query/has_parent_path.cc @@ -0,0 +1,44 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 8.4.9 path decomposition [path.decompose] + +#include <filesystem> +#include <vector> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +using std::filesystem::path; + +void +test01() +{ + for (const path& p : __gnu_test::test_paths) + { + VERIFY( p.has_parent_path() == !p.parent_path().empty() ); + } +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/query/has_relative_path.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/query/has_relative_path.cc new file mode 100644 index 00000000000..25e2dd5ea29 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/query/has_relative_path.cc @@ -0,0 +1,44 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 8.4.9 path decomposition [path.decompose] + +#include <filesystem> +#include <vector> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +using std::filesystem::path; + +void +test01() +{ + for (const path& p : __gnu_test::test_paths) + { + VERIFY( p.has_relative_path() == !p.relative_path().empty() ); + } +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/query/has_root_directory.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/query/has_root_directory.cc new file mode 100644 index 00000000000..66c8df20976 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/query/has_root_directory.cc @@ -0,0 +1,44 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 8.4.9 path decomposition [path.decompose] + +#include <filesystem> +#include <vector> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +using std::filesystem::path; + +void +test01() +{ + for (const path& p : __gnu_test::test_paths) + { + VERIFY( p.has_root_directory() == !p.root_directory().empty() ); + } +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/query/has_root_name.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/query/has_root_name.cc new file mode 100644 index 00000000000..f9d7157d646 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/query/has_root_name.cc @@ -0,0 +1,44 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 8.4.9 path decomposition [path.decompose] + +#include <filesystem> +#include <vector> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +using std::filesystem::path; + +void +test01() +{ + for (const path& p : __gnu_test::test_paths) + { + VERIFY( p.has_root_name() == !p.root_name().empty() ); + } +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/query/has_root_path.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/query/has_root_path.cc new file mode 100644 index 00000000000..f0bdb8156c6 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/query/has_root_path.cc @@ -0,0 +1,44 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 8.4.9 path decomposition [path.decompose] + +#include <filesystem> +#include <vector> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +using std::filesystem::path; + +void +test01() +{ + for (const path& p : __gnu_test::test_paths) + { + VERIFY( p.has_root_path() == !p.root_path().empty() ); + } +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/query/has_stem.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/query/has_stem.cc new file mode 100644 index 00000000000..18bf0159825 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/query/has_stem.cc @@ -0,0 +1,44 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 8.4.9 path decomposition [path.decompose] + +#include <filesystem> +#include <vector> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +using std::filesystem::path; + +void +test01() +{ + for (const path& p : __gnu_test::test_paths) + { + VERIFY( p.has_stem() == !p.stem().empty() ); + } +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/query/is_relative.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/query/is_relative.cc new file mode 100644 index 00000000000..c6f6c7f98b1 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/query/is_relative.cc @@ -0,0 +1,44 @@ +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +// Copyright (C) 2014-2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 8.4.9 path decomposition [path.decompose] + +#include <filesystem> +#include <vector> +#include <testsuite_hooks.h> +#include <testsuite_fs.h> + +using std::filesystem::path; + +void +test01() +{ + for (const path& p : __gnu_test::test_paths) + { + VERIFY( p.is_relative() == !p.is_absolute() ); + } +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/headers/fstream/synopsis.cc b/libstdc++-v3/testsuite/27_io/headers/fstream/synopsis.cc index f434f40ad2c..bc914b64698 100644 --- a/libstdc++-v3/testsuite/27_io/headers/fstream/synopsis.cc +++ b/libstdc++-v3/testsuite/27_io/headers/fstream/synopsis.cc @@ -1,4 +1,5 @@ // { dg-do compile } +// { dg-require-normal-namespace "" } // Copyright (C) 2007-2017 Free Software Foundation, Inc. // diff --git a/libstdc++-v3/testsuite/27_io/headers/ios/synopsis.cc b/libstdc++-v3/testsuite/27_io/headers/ios/synopsis.cc index c16d677fac2..1d3ba285166 100644 --- a/libstdc++-v3/testsuite/27_io/headers/ios/synopsis.cc +++ b/libstdc++-v3/testsuite/27_io/headers/ios/synopsis.cc @@ -1,4 +1,5 @@ // { dg-do compile } +// { dg-require-normal-namespace "" } // Copyright (C) 2007-2017 Free Software Foundation, Inc. // diff --git a/libstdc++-v3/testsuite/27_io/headers/istream/synopsis.cc b/libstdc++-v3/testsuite/27_io/headers/istream/synopsis.cc index 0173f1c30d1..894964a871a 100644 --- a/libstdc++-v3/testsuite/27_io/headers/istream/synopsis.cc +++ b/libstdc++-v3/testsuite/27_io/headers/istream/synopsis.cc @@ -1,4 +1,5 @@ // { dg-do compile } +// { dg-require-normal-namespace "" } // Copyright (C) 2007-2017 Free Software Foundation, Inc. // diff --git a/libstdc++-v3/testsuite/27_io/headers/ostream/synopsis.cc b/libstdc++-v3/testsuite/27_io/headers/ostream/synopsis.cc index 7529c7760ee..f3778cc1b2b 100644 --- a/libstdc++-v3/testsuite/27_io/headers/ostream/synopsis.cc +++ b/libstdc++-v3/testsuite/27_io/headers/ostream/synopsis.cc @@ -1,4 +1,5 @@ // { dg-do compile } +// { dg-require-normal-namespace "" } // Copyright (C) 2007-2017 Free Software Foundation, Inc. // diff --git a/libstdc++-v3/testsuite/27_io/headers/sstream/synopsis.cc b/libstdc++-v3/testsuite/27_io/headers/sstream/synopsis.cc index b925ee85a87..b7463685bf0 100644 --- a/libstdc++-v3/testsuite/27_io/headers/sstream/synopsis.cc +++ b/libstdc++-v3/testsuite/27_io/headers/sstream/synopsis.cc @@ -1,4 +1,5 @@ // { dg-do compile } +// { dg-require-normal-namespace "" } // Copyright (C) 2007-2017 Free Software Foundation, Inc. // diff --git a/libstdc++-v3/testsuite/27_io/headers/streambuf/synopsis.cc b/libstdc++-v3/testsuite/27_io/headers/streambuf/synopsis.cc index 2af15bbcfc4..93658ff7178 100644 --- a/libstdc++-v3/testsuite/27_io/headers/streambuf/synopsis.cc +++ b/libstdc++-v3/testsuite/27_io/headers/streambuf/synopsis.cc @@ -1,4 +1,5 @@ // { dg-do compile } +// { dg-require-normal-namespace "" } // Copyright (C) 2007-2017 Free Software Foundation, Inc. // diff --git a/libstdc++-v3/testsuite/decimal/conversion-to-integral.cc b/libstdc++-v3/testsuite/decimal/conversion-to-integral.cc index 6fd59a67b70..cc48fa8729d 100644 --- a/libstdc++-v3/testsuite/decimal/conversion-to-integral.cc +++ b/libstdc++-v3/testsuite/decimal/conversion-to-integral.cc @@ -64,7 +64,7 @@ void conversion_to_integral_128 (void) { #undef MAXVAL - #define MAXVAL LONG_LONG_MAX + #define MAXVAL __LONG_LONG_MAX__ decimal128 a, b (1), c (-1), d (MAXVAL), e (-MAXVAL); long long ll; diff --git a/libstdc++-v3/testsuite/experimental/filesystem/file_status/1.cc b/libstdc++-v3/testsuite/experimental/filesystem/file_status/1.cc new file mode 100644 index 00000000000..970ad177b95 --- /dev/null +++ b/libstdc++-v3/testsuite/experimental/filesystem/file_status/1.cc @@ -0,0 +1,75 @@ +// Copyright (C) 2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-options "-lstdc++fs" } +// { dg-do run { target c++11 } } +// { dg-require-filesystem-ts "" } + +#include <experimental/filesystem> +#include <testsuite_hooks.h> + +namespace fs = std::experimental::filesystem; + +template<typename... Args> +constexpr bool nothrow_constructible() { + return std::is_nothrow_constructible<fs::file_status, Args...>::value; +} + +void +test01() +{ + fs::file_status st0; + VERIFY( st0.type() == fs::file_type::none ); + VERIFY( st0.permissions() == fs::perms::unknown ); + static_assert( nothrow_constructible<>(), "" ); + + fs::file_status st1(fs::file_type::regular); + VERIFY( st1.type() == fs::file_type::regular ); + VERIFY( st1.permissions() == fs::perms::unknown ); + static_assert( nothrow_constructible<fs::file_type>(), "" ); + + fs::file_status st2(fs::file_type::directory, fs::perms::owner_all); + VERIFY( st2.type() == fs::file_type::directory ); + VERIFY( st2.permissions() == fs::perms::owner_all ); + static_assert( nothrow_constructible<fs::file_type, fs::perms>(), "" ); + + static_assert( nothrow_constructible<const fs::file_status&>(), "" ); + static_assert( nothrow_constructible<fs::file_status>(), "" ); +} + +void +test02() +{ + fs::file_status st; + VERIFY( st.type() == fs::file_type::none ); + VERIFY( st.permissions() == fs::perms::unknown ); + + st.type(fs::file_type::symlink); + VERIFY( st.type() == fs::file_type::symlink ); + VERIFY( st.permissions() == fs::perms::unknown ); + + st.permissions(fs::perms::owner_all); + VERIFY( st.type() == fs::file_type::symlink ); + VERIFY( st.permissions() == fs::perms::owner_all ); +} + +int +main() +{ + test01(); + test02(); +} 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 e7b5e53d43d..50cc7d45de8 100644 --- a/libstdc++-v3/testsuite/experimental/filesystem/iterators/recursive_directory_iterator.cc +++ b/libstdc++-v3/testsuite/experimental/filesystem/iterators/recursive_directory_iterator.cc @@ -28,6 +28,7 @@ namespace fs = std::experimental::filesystem; void test01() { + const std::error_code bad_ec = make_error_code(std::errc::invalid_argument); std::error_code ec; // Test non-existent path. @@ -37,15 +38,19 @@ test01() VERIFY( iter == end(iter) ); // Test empty directory. + ec = bad_ec; create_directory(p, fs::current_path(), ec); VERIFY( !ec ); + ec = bad_ec; iter = fs::recursive_directory_iterator(p, ec); VERIFY( !ec ); VERIFY( iter == end(iter) ); // Test non-empty directory. - create_directories(p / "d1/d2"); + ec = bad_ec; + create_directories(p / "d1/d2", ec); VERIFY( !ec ); + ec = bad_ec; iter = fs::recursive_directory_iterator(p, ec); VERIFY( !ec ); VERIFY( iter != end(iter) ); @@ -56,6 +61,7 @@ test01() VERIFY( iter == end(iter) ); // Test inaccessible directory. + ec = bad_ec; permissions(p, fs::perms::none, ec); VERIFY( !ec ); iter = fs::recursive_directory_iterator(p, ec); @@ -64,15 +70,19 @@ test01() // Test inaccessible directory, skipping permission denied. const auto opts = fs::directory_options::skip_permission_denied; + ec = bad_ec; iter = fs::recursive_directory_iterator(p, opts, ec); VERIFY( !ec ); VERIFY( iter == end(iter) ); // Test inaccessible sub-directory. + ec = bad_ec; permissions(p, fs::perms::owner_all, ec); VERIFY( !ec ); + ec = bad_ec; permissions(p/"d1/d2", fs::perms::none, ec); VERIFY( !ec ); + ec = bad_ec; iter = fs::recursive_directory_iterator(p, ec); VERIFY( !ec ); VERIFY( iter != end(iter) ); @@ -84,12 +94,14 @@ test01() VERIFY( iter == end(iter) ); // Test inaccessible sub-directory, skipping permission denied. + ec = bad_ec; iter = fs::recursive_directory_iterator(p, opts, ec); VERIFY( !ec ); VERIFY( iter != end(iter) ); VERIFY( iter->path() == p/"d1" ); ++iter; // should recurse into d1 VERIFY( iter->path() == p/"d1/d2" ); + ec = bad_ec; iter.increment(ec); // should fail to recurse into p/d1/d2, so skip it VERIFY( !ec ); VERIFY( iter == end(iter) ); @@ -101,12 +113,15 @@ test01() void test02() { + const std::error_code bad_ec = make_error_code(std::errc::invalid_argument); std::error_code ec; const auto p = __gnu_test::nonexistent_path(); + ec = bad_ec; create_directories(p / "d1/d2", ec); VERIFY( !ec ); // Test post-increment (libstdc++/71005) + ec = bad_ec; auto iter = fs::recursive_directory_iterator(p, ec); VERIFY( !ec ); VERIFY( iter != end(iter) ); @@ -126,7 +141,7 @@ test02() void test03() { - std::error_code ec; + std::error_code ec = make_error_code(std::errc::invalid_argument); const auto p = __gnu_test::nonexistent_path(); create_directories(p / "longer_than_small_string_buffer", ec); VERIFY( !ec ); diff --git a/libstdc++-v3/testsuite/experimental/filesystem/operations/create_directory.cc b/libstdc++-v3/testsuite/experimental/filesystem/operations/create_directory.cc index f1c50a6e8e3..85e8281a6e1 100644 --- a/libstdc++-v3/testsuite/experimental/filesystem/operations/create_directory.cc +++ b/libstdc++-v3/testsuite/experimental/filesystem/operations/create_directory.cc @@ -50,7 +50,6 @@ test01() VERIFY( !ec ); VERIFY( !b ); b = create_directory(p); - VERIFY( !ec ); VERIFY( !b ); remove_all(p, ec); diff --git a/libstdc++-v3/testsuite/experimental/filesystem/operations/temp_directory_path.cc b/libstdc++-v3/testsuite/experimental/filesystem/operations/temp_directory_path.cc index e8a6dd3cd85..1689a2a0775 100644 --- a/libstdc++-v3/testsuite/experimental/filesystem/operations/temp_directory_path.cc +++ b/libstdc++-v3/testsuite/experimental/filesystem/operations/temp_directory_path.cc @@ -43,7 +43,7 @@ test01() if (!fs::exists("/tmp")) return; // just give up - std::error_code ec; + std::error_code ec = make_error_code(std::errc::invalid_argument); fs::path p1 = fs::temp_directory_path(ec); VERIFY( !ec ); VERIFY( exists(p1) ); diff --git a/libstdc++-v3/testsuite/experimental/filesystem/path/construct/string_view.cc b/libstdc++-v3/testsuite/experimental/filesystem/path/construct/string_view.cc index fbf8bd4d6d3..6879909c777 100644 --- a/libstdc++-v3/testsuite/experimental/filesystem/path/construct/string_view.cc +++ b/libstdc++-v3/testsuite/experimental/filesystem/path/construct/string_view.cc @@ -24,6 +24,7 @@ #include <experimental/filesystem> #include <string_view> #include <string> +#define USE_FILESYSTEM_TS #include <testsuite_fs.h> using std::experimental::filesystem::path; diff --git a/libstdc++-v3/testsuite/experimental/filesystem/path/itr/traversal.cc b/libstdc++-v3/testsuite/experimental/filesystem/path/itr/traversal.cc index bc1091476b5..41a292af4db 100644 --- a/libstdc++-v3/testsuite/experimental/filesystem/path/itr/traversal.cc +++ b/libstdc++-v3/testsuite/experimental/filesystem/path/itr/traversal.cc @@ -79,9 +79,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(); } diff --git a/libstdc++-v3/testsuite/lib/dg-options.exp b/libstdc++-v3/testsuite/lib/dg-options.exp index 0dbf6592c14..57eff708eca 100644 --- a/libstdc++-v3/testsuite/lib/dg-options.exp +++ b/libstdc++-v3/testsuite/lib/dg-options.exp @@ -52,6 +52,15 @@ proc dg-require-normal-mode { args } { return } +proc dg-require-normal-namespace { args } { + if { ![ check_v3_target_normal_namespace ] } { + upvar dg-do-what dg-do-what + set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"] + return + } + return +} + proc dg-require-parallel-mode { args } { if { ![ check_v3_target_parallel_mode ] } { upvar dg-do-what dg-do-what diff --git a/libstdc++-v3/testsuite/lib/libstdc++.exp b/libstdc++-v3/testsuite/lib/libstdc++.exp index b081d8a5b90..02c88ede2ab 100644 --- a/libstdc++-v3/testsuite/lib/libstdc++.exp +++ b/libstdc++-v3/testsuite/lib/libstdc++.exp @@ -126,7 +126,7 @@ proc libstdc++_init { testfile } { # If a test doesn't have special options, use DEFAULT_CXXFLAGS. # Use this variable if the behavior # 1) only applies to libstdc++ testing - # 2) might need to be negated + # 2) might need to be negated # In particular, some tests have to be run without precompiled # headers, or without assertions. @@ -135,10 +135,10 @@ proc libstdc++_init { testfile } { # Host specific goo here. if { [string match "powerpc-*-darwin*" $target_triplet] } { append DEFAULT_CXXFLAGS " -multiply_defined suppress" - } + } if { [string match "powerpc-ibm-aix*" $target_triplet] } { append DEFAULT_CXXFLAGS " -Wl,-bmaxdata:0x20000000" - } + } } v3track DEFAULT_CXXFLAGS 2 @@ -156,7 +156,7 @@ proc libstdc++_init { testfile } { # SHLIB_EXT on different platforms set gccdir [lookfor_file $tool_root_dir gcc/libgcc.a] if {$gccdir != ""} { - set gccdir [file dirname $gccdir] + set gccdir [file dirname $gccdir] append ld_library_path_tmp ":${gccdir}" } v3track gccdir 3 @@ -166,7 +166,7 @@ proc libstdc++_init { testfile } { set libgompdir [lookfor_file $blddir/../libgomp .libs/libgomp.$shlib_ext] if {$libgompdir != ""} { set v3-libgomp 1 - set libgompdir [file dirname $libgompdir] + set libgompdir [file dirname $libgompdir] append ld_library_path_tmp ":${libgompdir}" verbose -log "libgomp support detected" } @@ -177,7 +177,7 @@ proc libstdc++_init { testfile } { set libvtvdir [lookfor_file $blddir/../libvtv .libs/libvtv.$shlib_ext] if {$libvtvdir != ""} { set v3-libvtv 1 - set libvtvdir [file dirname $libvtvdir] + set libvtvdir [file dirname $libvtvdir] append ld_library_path_tmp ":${libvtvdir}" verbose -log "libvtv support detected" } @@ -193,7 +193,7 @@ proc libstdc++_init { testfile } { && [isnative] } then { set v3-sharedlib 1 verbose -log "shared library support detected" - } + } } v3track v3-sharedlib 3 @@ -252,25 +252,25 @@ proc libstdc++_init { testfile } { # $srcdir so we copy the testsuite headers into the current # directory, and then add that to the search path. foreach src [glob "${srcdir}/util/*.h" \ - "${srcdir}/util/*.cc" \ - "${srcdir}/util/*.tcc" \ - "${srcdir}/util/*.hpp" \ - "${srcdir}/util/*/*.h" \ - "${srcdir}/util/*/*.cc" \ - "${srcdir}/util/*/*.tcc" \ + "${srcdir}/util/*.cc" \ + "${srcdir}/util/*.tcc" \ + "${srcdir}/util/*.hpp" \ + "${srcdir}/util/*/*.h" \ + "${srcdir}/util/*/*.cc" \ + "${srcdir}/util/*/*.tcc" \ "${srcdir}/util/*/*.hpp" \ - "${srcdir}/util/*/*/*.h" \ - "${srcdir}/util/*/*/*.cc" \ - "${srcdir}/util/*/*/*.tcc" \ + "${srcdir}/util/*/*/*.h" \ + "${srcdir}/util/*/*/*.cc" \ + "${srcdir}/util/*/*/*.tcc" \ "${srcdir}/util/*/*/*.hpp" \ - "${srcdir}/util/*/*/*/*.h" \ - "${srcdir}/util/*/*/*/*.cc" \ - "${srcdir}/util/*/*/*/*.tcc" \ - "${srcdir}/util/*/*/*/*.hpp" \ - "${srcdir}/util/*/*/*/*/*.h" \ - "${srcdir}/util/*/*/*/*/*.cc" \ - "${srcdir}/util/*/*/*/*/*.tcc" \ - "${srcdir}/util/*/*/*/*/*.hpp" ] { + "${srcdir}/util/*/*/*/*.h" \ + "${srcdir}/util/*/*/*/*.cc" \ + "${srcdir}/util/*/*/*/*.tcc" \ + "${srcdir}/util/*/*/*/*.hpp" \ + "${srcdir}/util/*/*/*/*/*.h" \ + "${srcdir}/util/*/*/*/*/*.cc" \ + "${srcdir}/util/*/*/*/*/*.tcc" \ + "${srcdir}/util/*/*/*/*/*.hpp" ] { # Remove everything up to "util/..." set dst [string range $src [string length "${srcdir}/"] end] # Create the directory containing the file. @@ -285,7 +285,7 @@ proc libstdc++_init { testfile } { } set includes "-Iutil" } elseif { [file exists $flags_file] } { - # If we find a testsuite_flags file, we're testing in the build dir. + # If we find a testsuite_flags file, we're testing in the build dir. set cxx [exec sh $flags_file --build-cxx] set cxxflags [exec sh $flags_file --cxxflags] set cxxpchflags [exec sh $flags_file --cxxpchflags] @@ -328,9 +328,9 @@ proc libstdc++_init { testfile } { verbose -log "Requested PCH file: $cxxpchflags" verbose -log "is not working, and will not be used." set cxxpchflags "" - } + } file delete $src - } + } v3track cxxpchflags 2 global PCH_CXXFLAGS @@ -356,36 +356,36 @@ proc libstdc++_exit { } { proc libstdc++-dg-test { prog do_what extra_tool_flags } { # Set up the compiler flags, based on what we're going to do. switch $do_what { - "preprocess" { - set compile_type "preprocess" - set output_file "[file rootname [file tail $prog]].i" - } - "compile" { - set compile_type "assembly" - set output_file "[file rootname [file tail $prog]].s" - } - "assemble" { - set compile_type "object" - set output_file "[file rootname [file tail $prog]].o" - } - "link" { - set compile_type "executable" - set output_file "./[file rootname [file tail $prog]].exe" - } - "run" { - set compile_type "executable" - # FIXME: "./" is to cope with "." not being in $PATH. - # Should this be handled elsewhere? - # YES. - set output_file "./[file rootname [file tail $prog]].exe" - # This is the only place where we care if an executable was - # created or not. If it was, dg.exp will try to run it. - catch { remote_file build delete $output_file } - } + "preprocess" { + set compile_type "preprocess" + set output_file "[file rootname [file tail $prog]].i" + } + "compile" { + set compile_type "assembly" + set output_file "[file rootname [file tail $prog]].s" + } + "assemble" { + set compile_type "object" + set output_file "[file rootname [file tail $prog]].o" + } + "link" { + set compile_type "executable" + set output_file "./[file rootname [file tail $prog]].exe" + } + "run" { + set compile_type "executable" + # FIXME: "./" is to cope with "." not being in $PATH. + # Should this be handled elsewhere? + # YES. + set output_file "./[file rootname [file tail $prog]].exe" + # This is the only place where we care if an executable was + # created or not. If it was, dg.exp will try to run it. + catch { remote_file build delete $output_file } + } default { - perror "$do_what: not a valid dg-do keyword" - return "" - } + perror "$do_what: not a valid dg-do keyword" + return "" + } } # Short-circut a bunch of complicated goo here for the special @@ -404,7 +404,7 @@ proc libstdc++-dg-test { prog do_what extra_tool_flags } { regsub -all ".x c" $edit_tool_flags "" edit_tool_flags lappend options "additional_flags=$edit_tool_flags" set select_compile "v3_target_compile_as_c" - } else { + } else { lappend options "additional_flags=$extra_tool_flags" } } @@ -461,7 +461,7 @@ set v3-symver 0 # Called from libstdc++-dg-test above. Calls back into system's # target_compile to actually do the work. proc v3_target_compile { source dest type options } { - global gluefile + global gluefile global wrap_flags global cxx global cxxflags @@ -474,8 +474,8 @@ proc v3_target_compile { source dest type options } { lappend options "additional_flags=-fno-diagnostics-show-caret -fdiagnostics-color=never" if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } { - lappend options "libs=${gluefile}" - lappend options "ldflags=${wrap_flags}" + lappend options "libs=${gluefile}" + lappend options "ldflags=${wrap_flags}" } set cxx_final $cxx @@ -509,7 +509,7 @@ proc v3_target_compile { source dest type options } { # Called from libstdc++-dg-test above, but only for "C" compilation. # Calls back into system's target_compile to actually do the work. proc v3_target_compile_as_c { source dest type options } { - global gluefile + global gluefile global wrap_flags global includes global flags_file @@ -520,8 +520,8 @@ proc v3_target_compile_as_c { source dest type options } { global tool if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } { - lappend options "libs=${gluefile}" - lappend options "ldflags=${wrap_flags}" + lappend options "libs=${gluefile}" + lappend options "ldflags=${wrap_flags}" } set tname [target_info name] @@ -554,15 +554,15 @@ proc v3_target_compile_as_c { source dest type options } { set crossbase "${comp_base_dir}/${machine}/include/c++/${version}" set crosstarget "${crossbase}/${machine}" set cc_final [concat $cc_final "-I$crossbase -I$crosstarget"] - # For a native compiler, the header files will be located at + # For a native compiler, the header files will be located at # the top level. set includesbase "${comp_base_dir}/include/c++/${version}" set includestarget "${includesbase}/${machine}" set cc_final [concat $cc_final "-I$includesbase -I$includestarget"] - set libdir "-L${comp_base_dir}/lib" + set libdir "-L${comp_base_dir}/lib" } else { - set libdir "-L${blddir}/libsupc++/.libs" + set libdir "-L${blddir}/libsupc++/.libs" set libdir [concat $libdir "-L${blddir}/src/.libs"] } @@ -632,14 +632,14 @@ proc v3-build_support { } { # Build the support objects. set source_files [list testsuite_abi.cc testsuite_allocator.cc \ testsuite_character.cc testsuite_hooks.cc \ - io/verified_cmd_line_input.cc \ + io/verified_cmd_line_input.cc \ io/prog_bar.cc performance/time/elapsed_timer.cc ] foreach f $source_files { set obj [file rootname $f].o set object_file [file tail $obj] # Compile with "-w" so that warnings issued by the compiler # do not prevent compilation. - # Disable LTO so that ar/ranlib don't need the LTO plugin. + # Disable LTO so that ar/ranlib don't need the LTO plugin. if { [v3_target_compile $srcdir/util/$f $object_file "object" \ [list "incdir=$srcdir" "additional_flags=-w -fno-lto"]] != "" } { @@ -691,7 +691,7 @@ proc v3-build_support { } { proc check_v3_target_fileio { } { global et_fileio_saved global et_fileio_target_name - global tool + global tool global srcdir if { ![info exists et_fileio_target_name] } { @@ -728,7 +728,7 @@ proc check_v3_target_fileio { } { puts $f "#include <unistd.h>" puts $f "#include <errno.h>" puts $f "#include <string.h>" - puts $f "using namespace std;" + puts $f "using namespace std;" puts $f "int main ()" puts $f "{" puts $f " int fd = open (\"$testfile\", O_RDONLY);" @@ -751,7 +751,7 @@ proc check_v3_target_fileio { } { puts $f " close (fd);" puts $f " }" puts $f " return ret;" - puts $f "}" + puts $f "}" close $f set lines [v3_target_compile $src $exe executable ""] @@ -779,7 +779,7 @@ proc check_v3_target_fileio { } { proc check_v3_target_c_std { } { global et_c_std_saved global et_c_std_target_name - global tool + global tool if { ![info exists et_c_std_target_name] } { set et_c_std_target_name "" @@ -803,7 +803,7 @@ proc check_v3_target_c_std { } { # Set up, compile, and execute a C++ test program that tries to use # C99 functionality. - # For math bits, could use check_effective_target_c99_math. + # For math bits, could use check_effective_target_c99_math. set src fileio[pid].cc set exe fileio[pid].x @@ -817,7 +817,7 @@ proc check_v3_target_c_std { } { puts $f " " puts $f " using std::wctomb;" puts $f " return i;" - puts $f "}" + puts $f "}" close $f set lines [v3_target_compile $src $exe executable ""] @@ -849,7 +849,7 @@ proc check_v3_target_sharedlib { } { proc check_v3_target_time { } { global et_time_saved global et_time_target_name - global tool + global tool if { ![info exists et_time_target_name] } { set et_time_target_name "" @@ -877,11 +877,11 @@ proc check_v3_target_time { } { set f [open $src "w"] puts $f "#include <time.h>" - puts $f "using namespace std;" + puts $f "using namespace std;" puts $f "int main ()" puts $f "{" - puts $f " time (0);" - puts $f "}" + puts $f " time (0);" + puts $f "}" close $f set lines [v3_target_compile $src /dev/null executable ""] @@ -956,12 +956,12 @@ proc check_v3_target_namedlocale { args } { file delete $src if ![string match "" $lines] { - verbose "check_v3_target_namedlocale: compilation failed" 2 - return $et_namedlocale + verbose "check_v3_target_namedlocale: compilation failed" 2 + return $et_namedlocale } # else No error message, compilation succeeded. } - + set result [${tool}_load "./$exe" "$args" ""] set status [lindex $result 0] @@ -975,7 +975,7 @@ proc check_v3_target_namedlocale { args } { proc check_v3_target_debug_mode { } { global et_debug_mode - global tool + global tool if { ![info exists et_debug_mode_target_name] } { set et_debug_mode_target_name "" @@ -1067,7 +1067,7 @@ proc check_v3_target_profile_mode { } { proc check_v3_target_normal_mode { } { global et_normal_mode - global tool + global tool if { ![info exists et_normal_mode_target_name] } { set et_normal_mode_target_name "" @@ -1094,7 +1094,10 @@ proc check_v3_target_normal_mode { } { set src normal_mode[pid].cc set f [open $src "w"] - puts $f "#if defined(_GLIBCXX_DEBUG) || defined(_GLIBCXX_PROFILE) || defined(_GLIBCXX_PARALLEL)" + puts $f "#include <bits/c++config.h>" + puts $f "#if defined(_GLIBCXX_DEBUG) || \\" + puts $f " defined(_GLIBCXX_PROFILE) || \\" + puts $f " defined(_GLIBCXX_PARALLEL)" puts $f "# error No normal mode" puts $f "#endif" close $f @@ -1111,12 +1114,59 @@ proc check_v3_target_normal_mode { } { return $et_normal_mode } +proc check_v3_target_normal_namespace { } { + global et_normal_namespace + global tool + + if { ![info exists et_normal_namespace_target_name] } { + set et_normal_namespace_target_name "" + } + + # If the target has changed since we set the cached value, clear it. + set current_target [current_target_name] + if { $current_target != $et_normal_namespace_target_name } { + verbose "check_v3_target_normal_namespace: `$et_normal_namespace_target_name'" 2 + set et_normal_namespace_target_name $current_target + if [info exists et_normal_namespace] { + verbose "check_v3_target_normal_namespace: removing cached result" 2 + unset et_normal_namespace + } + } + + if [info exists et_normal_namespace] { + verbose "check_v3_target_normal_namespace: using cached result" 2 + } else { + set et_normal_namespace 0 + + # Set up and compile a C++ test program that depends + # on normal std namespace. + set src normal_namespace[pid].cc + + set f [open $src "w"] + puts $f "#include <bits/c++config.h>" + puts $f "#if _GLIBCXX_INLINE_VERSION" + puts $f "# error No normal namespace" + puts $f "#endif" + close $f + + set lines [v3_target_compile $src /dev/null preprocess ""] + file delete $src + + if [string match "" $lines] { + # No error message, compilation succeeded. + set et_normal_namespace 1 + } + } + verbose "check_v3_target_normal_namespace: $et_normal_namespace" 2 + return $et_normal_namespace +} + proc check_v3_target_parallel_mode { } { global cxxflags global v3-libgomp global et_parallel_mode - global tool + global tool if { ![info exists et_parallel_mode_target_name] } { set et_parallel_mode_target_name "" @@ -1152,7 +1202,7 @@ proc check_v3_target_cstdint { } { global DEFAULT_CXXFLAGS global et_cstdint - global tool + global tool if { ![info exists et_cstdint_target_name] } { set et_cstdint_target_name "" @@ -1381,49 +1431,49 @@ proc check_v3_target_gthreads { } { global tool if { ![info exists et_gthreads_target_name] } { - set et_gthreads_target_name "" + set et_gthreads_target_name "" } # If the target has changed since we set the cached value, clear it. set current_target [current_target_name] if { $current_target != $et_gthreads_target_name } { - verbose "check_v3_target_gthreads: `$et_gthreads_target_name'" 2 - set et_gthreads_target_name $current_target - if [info exists et_gthreads] { - verbose "check_v3_target_gthreads: removing cached result" 2 - unset et_gthreads - } + verbose "check_v3_target_gthreads: `$et_gthreads_target_name'" 2 + set et_gthreads_target_name $current_target + if [info exists et_gthreads] { + verbose "check_v3_target_gthreads: removing cached result" 2 + unset et_gthreads + } } if [info exists et_gthreads] { - verbose "check_v3_target_gthreads: using cached result" 2 + verbose "check_v3_target_gthreads: using cached result" 2 } else { - set et_gthreads 0 + set et_gthreads 0 - # Set up and preprocess a C++0x test program that depends - # on the gthreads facilities to be available. - set src gthreads[pid].cc + # Set up and preprocess a C++0x test program that depends + # on the gthreads facilities to be available. + set src gthreads[pid].cc - set f [open $src "w"] + set f [open $src "w"] puts $f "#include <bits/c++config.h>" - puts $f "#ifndef _GLIBCXX_HAS_GTHREADS" - puts $f "# error No gthread" - puts $f "#endif" - close $f + puts $f "#ifndef _GLIBCXX_HAS_GTHREADS" + puts $f "# error No gthread" + puts $f "#endif" + close $f - set cxxflags_saved $cxxflags - set cxxflags "$cxxflags $DEFAULT_CXXFLAGS -Werror" + set cxxflags_saved $cxxflags + set cxxflags "$cxxflags $DEFAULT_CXXFLAGS -Werror" - set lines [v3_target_compile $src /dev/null preprocess ""] - set cxxflags $cxxflags_saved - file delete $src + set lines [v3_target_compile $src /dev/null preprocess ""] + set cxxflags $cxxflags_saved + file delete $src - if [string match "" $lines] { - # No error message, preprocessing succeeded. - set et_gthreads 1 - } else { - verbose "check_v3_target_gthreads: compilation failed" 2 - } + if [string match "" $lines] { + # No error message, preprocessing succeeded. + set et_gthreads 1 + } else { + verbose "check_v3_target_gthreads: compilation failed" 2 + } } verbose "check_v3_target_gthreads: $et_gthreads" 2 return $et_gthreads @@ -1437,52 +1487,52 @@ proc check_v3_target_gthreads_timed { } { global tool if { ![info exists et_gthreads_timed_target_name] } { - set et_gthreads_timed_target_name "" + set et_gthreads_timed_target_name "" } # If the target has changed since we set the cached value, clear it. set current_target [current_target_name] if { $current_target != $et_gthreads_timed_target_name } { - verbose "check_v3_target_gthreads_timed: `$et_gthreads_timed_target_name'" 2 - set et_gthreads_timed_target_name $current_target - if [info exists et_gthreads_timed] { - verbose "check_v3_target_gthreads_timed: removing cached result" 2 - unset et_gthreads_timed - } + verbose "check_v3_target_gthreads_timed: `$et_gthreads_timed_target_name'" 2 + set et_gthreads_timed_target_name $current_target + if [info exists et_gthreads_timed] { + verbose "check_v3_target_gthreads_timed: removing cached result" 2 + unset et_gthreads_timed + } } if [info exists et_gthreads_timed] { - verbose "check_v3_target_gthreads_timed: using cached result" 2 + verbose "check_v3_target_gthreads_timed: using cached result" 2 } else { - set et_gthreads_timed 0 + set et_gthreads_timed 0 - # Set up and preprocess a C++0x test program that depends - # on the gthreads timed mutex facilities to be available. - set src gthreads_timed[pid].cc + # Set up and preprocess a C++0x test program that depends + # on the gthreads timed mutex facilities to be available. + set src gthreads_timed[pid].cc - set f [open $src "w"] + set f [open $src "w"] puts $f "#include <bits/c++config.h>" - puts $f "#ifndef _GLIBCXX_HAS_GTHREADS" - puts $f "# error No gthread" - puts $f "#endif" - puts $f "#if !_GTHREAD_USE_MUTEX_TIMEDLOCK" - puts $f "# error No gthread timed mutexes" - puts $f "#endif" - close $f - - set cxxflags_saved $cxxflags - set cxxflags "$cxxflags $DEFAULT_CXXFLAGS -Werror" - - set lines [v3_target_compile $src /dev/null preprocess ""] - set cxxflags $cxxflags_saved - file delete $src - - if [string match "" $lines] { - # No error message, preprocessing succeeded. - set et_gthreads_timed 1 - } else { - verbose "check_v3_target_gthreads_timed: compilation failed" 2 - } + puts $f "#ifndef _GLIBCXX_HAS_GTHREADS" + puts $f "# error No gthread" + puts $f "#endif" + puts $f "#if !_GTHREAD_USE_MUTEX_TIMEDLOCK" + puts $f "# error No gthread timed mutexes" + puts $f "#endif" + close $f + + set cxxflags_saved $cxxflags + set cxxflags "$cxxflags $DEFAULT_CXXFLAGS -Werror" + + set lines [v3_target_compile $src /dev/null preprocess ""] + set cxxflags $cxxflags_saved + file delete $src + + if [string match "" $lines] { + # No error message, preprocessing succeeded. + set et_gthreads_timed 1 + } else { + verbose "check_v3_target_gthreads_timed: compilation failed" 2 + } } verbose "check_v3_target_gthreads_timed: $et_gthreads_timed" 2 return $et_gthreads_timed @@ -1497,51 +1547,51 @@ proc check_v3_target_sleep { } { global tool if { ![info exists et_sleep_target_name] } { - set et_sleep_target_name "" + set et_sleep_target_name "" } # If the target has changed since we set the cached value, clear it. set current_target [current_target_name] if { $current_target != $et_sleep_target_name } { - verbose "check_v3_target_sleep: `$et_sleep_target_name'" 2 - set et_sleep_target_name $current_target - if [info exists et_sleep] { - verbose "check_v3_target_sleep: removing cached result" 2 - unset et_sleep - } + verbose "check_v3_target_sleep: `$et_sleep_target_name'" 2 + set et_sleep_target_name $current_target + if [info exists et_sleep] { + verbose "check_v3_target_sleep: removing cached result" 2 + unset et_sleep + } } if [info exists et_sleep] { - verbose "check_v3_target_sleep: using cached result" 2 + verbose "check_v3_target_sleep: using cached result" 2 } else { - set et_sleep 0 + set et_sleep 0 # Set up and preprocess a C++11 test program that depends - # on the sleep facilities to be available. - set src sleep[pid].cc - - set f [open $src "w"] - puts $f "#include <bits/c++config.h>" - puts $f "#ifndef _GLIBCXX_USE_NANOSLEEP" - puts $f "# ifndef _GLIBCXX_HAVE_SLEEP" - puts $f "# error No nanosleep or sleep" - puts $f "# endif" - puts $f "#endif" - close $f - - set cxxflags_saved $cxxflags - set cxxflags "$cxxflags $DEFAULT_CXXFLAGS -Werror" - - set lines [v3_target_compile $src /dev/null preprocess ""] - set cxxflags $cxxflags_saved - file delete $src - - if [string match "" $lines] { - # No error message, preprocessing succeeded. - set et_sleep 1 - } else { - verbose "check_v3_target_sleep: compilation failed" 2 - } + # on the sleep facilities to be available. + set src sleep[pid].cc + + set f [open $src "w"] + puts $f "#include <bits/c++config.h>" + puts $f "#ifndef _GLIBCXX_USE_NANOSLEEP" + puts $f "# ifndef _GLIBCXX_HAVE_SLEEP" + puts $f "# error No nanosleep or sleep" + puts $f "# endif" + puts $f "#endif" + close $f + + set cxxflags_saved $cxxflags + set cxxflags "$cxxflags $DEFAULT_CXXFLAGS -Werror" + + set lines [v3_target_compile $src /dev/null preprocess ""] + set cxxflags $cxxflags_saved + file delete $src + + if [string match "" $lines] { + # No error message, preprocessing succeeded. + set et_sleep 1 + } else { + verbose "check_v3_target_sleep: compilation failed" 2 + } } verbose "check_v3_target_sleep: $et_sleep" 2 return $et_sleep @@ -1555,49 +1605,49 @@ proc check_v3_target_sched_yield { } { global tool if { ![info exists et_sched_yield_target_name] } { - set et_sched_yield_target_name "" + set et_sched_yield_target_name "" } # If the target has changed since we set the cached value, clear it. set current_target [current_target_name] if { $current_target != $et_sched_yield_target_name } { - verbose "check_v3_target_sched_yield: `$et_sched_yield_target_name'" 2 - set et_sched_yield_target_name $current_target - if [info exists et_sched_yield] { - verbose "check_v3_target_sched_yield: removing cached result" 2 - unset et_sched_yield - } + verbose "check_v3_target_sched_yield: `$et_sched_yield_target_name'" 2 + set et_sched_yield_target_name $current_target + if [info exists et_sched_yield] { + verbose "check_v3_target_sched_yield: removing cached result" 2 + unset et_sched_yield + } } if [info exists et_sched_yield] { - verbose "check_v3_target_sched_yield: using cached result" 2 + verbose "check_v3_target_sched_yield: using cached result" 2 } else { - set et_sched_yield 0 + set et_sched_yield 0 - # Set up and preprocess a C++0x test program that depends - # on the sched_yield facility to be available. - set src sched_yield[pid].cc + # Set up and preprocess a C++0x test program that depends + # on the sched_yield facility to be available. + set src sched_yield[pid].cc - set f [open $src "w"] - puts $f "#include <bits/c++config.h>" - puts $f "#ifndef _GLIBCXX_USE_SCHED_YIELD" - puts $f "# error No sched yield" - puts $f "#endif" - close $f + set f [open $src "w"] + puts $f "#include <bits/c++config.h>" + puts $f "#ifndef _GLIBCXX_USE_SCHED_YIELD" + puts $f "# error No sched yield" + puts $f "#endif" + close $f - set cxxflags_saved $cxxflags - set cxxflags "$cxxflags $DEFAULT_CXXFLAGS -Werror" + set cxxflags_saved $cxxflags + set cxxflags "$cxxflags $DEFAULT_CXXFLAGS -Werror" - set lines [v3_target_compile $src /dev/null preprocess ""] - set cxxflags $cxxflags_saved - file delete $src + set lines [v3_target_compile $src /dev/null preprocess ""] + set cxxflags $cxxflags_saved + file delete $src - if [string match "" $lines] { - # No error message, preprocessing succeeded. - set et_sched_yield 1 - } else { - verbose "check_v3_target_sched_yield: compilation failed" 2 - } + if [string match "" $lines] { + # No error message, preprocessing succeeded. + set et_sched_yield 1 + } else { + verbose "check_v3_target_sched_yield: compilation failed" 2 + } } verbose "check_v3_target_sched_yield: $et_sched_yield" 2 return $et_sched_yield @@ -1611,49 +1661,49 @@ proc check_v3_target_string_conversions { } { global tool if { ![info exists et_string_conversions_target_name] } { - set et_string_conversions_target_name "" + set et_string_conversions_target_name "" } # If the target has changed since we set the cached value, clear it. set current_target [current_target_name] if { $current_target != $et_string_conversions_target_name } { - verbose "check_v3_target_string_conversions: `$et_string_conversions_target_name'" 2 - set et_string_conversions_target_name $current_target - if [info exists et_string_conversions] { - verbose "check_v3_target_string_conversions: removing cached result" 2 - unset et_string_conversions - } + verbose "check_v3_target_string_conversions: `$et_string_conversions_target_name'" 2 + set et_string_conversions_target_name $current_target + if [info exists et_string_conversions] { + verbose "check_v3_target_string_conversions: removing cached result" 2 + unset et_string_conversions + } } if [info exists et_string_conversions] { - verbose "check_v3_target_string_conversions: using cached result" 2 + verbose "check_v3_target_string_conversions: using cached result" 2 } else { - set et_string_conversions 0 + set et_string_conversions 0 # Set up and preprocess a C++0x test program that depends - # on the string_conversions facilities to be available. - set src string_conversions[pid].cc - - set f [open $src "w"] - puts $f "#include <bits/c++config.h>" - puts $f "#if !(_GLIBCXX_USE_C99_STDIO && _GLIBCXX_USE_C99_STDLIB && _GLIBCXX_USE_C99_WCHAR) || defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF)" - puts $f "# error No string conversions" - puts $f "#endif" - close $f - - set cxxflags_saved $cxxflags - set cxxflags "$cxxflags $DEFAULT_CXXFLAGS -Werror" - - set lines [v3_target_compile $src /dev/null preprocess ""] - set cxxflags $cxxflags_saved - file delete $src - - if [string match "" $lines] { - # No error message, preprocessing succeeded. - set et_string_conversions 1 - } else { - verbose "check_v3_target_string_conversions: compilation failed" 2 - } + # on the string_conversions facilities to be available. + set src string_conversions[pid].cc + + set f [open $src "w"] + puts $f "#include <bits/c++config.h>" + puts $f "#if !(_GLIBCXX_USE_C99_STDIO && _GLIBCXX_USE_C99_STDLIB && _GLIBCXX_USE_C99_WCHAR) || defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF)" + puts $f "# error No string conversions" + puts $f "#endif" + close $f + + set cxxflags_saved $cxxflags + set cxxflags "$cxxflags $DEFAULT_CXXFLAGS -Werror" + + set lines [v3_target_compile $src /dev/null preprocess ""] + set cxxflags $cxxflags_saved + file delete $src + + if [string match "" $lines] { + # No error message, preprocessing succeeded. + set et_string_conversions 1 + } else { + verbose "check_v3_target_string_conversions: compilation failed" 2 + } } verbose "check_v3_target_string_conversions: $et_string_conversions" 2 return $et_string_conversions @@ -1667,49 +1717,49 @@ proc check_v3_target_swprintf { } { global tool if { ![info exists et_swprintf_target_name] } { - set et_swprintf_target_name "" + set et_swprintf_target_name "" } # If the target has changed since we set the cached value, clear it. set current_target [current_target_name] if { $current_target != $et_swprintf_target_name } { - verbose "check_v3_target_swprintf: `$et_swprintf_target_name'" 2 - set et_swprintf_target_name $current_target - if [info exists et_swprintf] { - verbose "check_v3_target_swprintf: removing cached result" 2 - unset et_swprintf - } + verbose "check_v3_target_swprintf: `$et_swprintf_target_name'" 2 + set et_swprintf_target_name $current_target + if [info exists et_swprintf] { + verbose "check_v3_target_swprintf: removing cached result" 2 + unset et_swprintf + } } if [info exists et_swprintf] { - verbose "check_v3_target_swprintf: using cached result" 2 + verbose "check_v3_target_swprintf: using cached result" 2 } else { - set et_swprintf 0 + set et_swprintf 0 # Set up and preprocess a C++0x test program that depends - # on a standard swprintf function to be available. - set src swprintf[pid].cc - - set f [open $src "w"] - puts $f "#include <bits/c++config.h>" - puts $f "#if defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF)" - puts $f "# error No swprintf" - puts $f "#endif" - close $f - - set cxxflags_saved $cxxflags - set cxxflags "$cxxflags $DEFAULT_CXXFLAGS -Werror" - - set lines [v3_target_compile $src /dev/null preprocess ""] - set cxxflags $cxxflags_saved - file delete $src - - if [string match "" $lines] { - # No error message, preprocessing succeeded. - set et_swprintf 1 - } else { - verbose "check_v3_target_swprintf: compilation failed" 2 - } + # on a standard swprintf function to be available. + set src swprintf[pid].cc + + set f [open $src "w"] + puts $f "#include <bits/c++config.h>" + puts $f "#if defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF)" + puts $f "# error No swprintf" + puts $f "#endif" + close $f + + set cxxflags_saved $cxxflags + set cxxflags "$cxxflags $DEFAULT_CXXFLAGS -Werror" + + set lines [v3_target_compile $src /dev/null preprocess ""] + set cxxflags $cxxflags_saved + file delete $src + + if [string match "" $lines] { + # No error message, preprocessing succeeded. + set et_swprintf 1 + } else { + verbose "check_v3_target_swprintf: compilation failed" 2 + } } verbose "check_v3_target_swprintf: $et_swprintf" 2 return $et_swprintf @@ -1723,49 +1773,49 @@ proc check_v3_target_binary_io { } { global tool if { ![info exists et_binary_io_target_name] } { - set et_binary_io_target_name "" + set et_binary_io_target_name "" } # If the target has changed since we set the cached value, clear it. set current_target [current_target_name] if { $current_target != $et_binary_io_target_name } { - verbose "check_v3_target_binary_io: `$et_binary_io_target_name'" 2 - set et_binary_io_target_name $current_target - if [info exists et_binary_io] { - verbose "check_v3_target_binary_io: removing cached result" 2 - unset et_binary_io - } + verbose "check_v3_target_binary_io: `$et_binary_io_target_name'" 2 + set et_binary_io_target_name $current_target + if [info exists et_binary_io] { + verbose "check_v3_target_binary_io: removing cached result" 2 + unset et_binary_io + } } if [info exists et_binary_io] { - verbose "check_v3_target_binary_io: using cached result" 2 + verbose "check_v3_target_binary_io: using cached result" 2 } else { - set et_binary_io 0 + set et_binary_io 0 # Set up and preprocess a C++0x test program that depends - # on text and binary I/O being the same. - set src binary_io[pid].cc - - set f [open $src "w"] - puts $f "#include <bits/c++config.h>" - puts $f "#if defined(_GLIBCXX_HAVE_DOS_BASED_FILESYSTEM)" - puts $f "# error No binary io" - puts $f "#endif" - close $f - - set cxxflags_saved $cxxflags - set cxxflags "$cxxflags $DEFAULT_CXXFLAGS -Werror" - - set lines [v3_target_compile $src /dev/null preprocess ""] - set cxxflags $cxxflags_saved - file delete $src - - if [string match "" $lines] { - # No error message, preprocessing succeeded. - set et_binary_io 1 - } else { - verbose "check_v3_target_binary_io: compilation failed" 2 - } + # on text and binary I/O being the same. + set src binary_io[pid].cc + + set f [open $src "w"] + puts $f "#include <bits/c++config.h>" + puts $f "#if defined(_GLIBCXX_HAVE_DOS_BASED_FILESYSTEM)" + puts $f "# error No binary io" + puts $f "#endif" + close $f + + set cxxflags_saved $cxxflags + set cxxflags "$cxxflags $DEFAULT_CXXFLAGS -Werror" + + set lines [v3_target_compile $src /dev/null preprocess ""] + set cxxflags $cxxflags_saved + file delete $src + + if [string match "" $lines] { + # No error message, preprocessing succeeded. + set et_binary_io 1 + } else { + verbose "check_v3_target_binary_io: compilation failed" 2 + } } verbose "check_v3_target_binary_io: $et_binary_io" 2 return $et_binary_io @@ -1803,7 +1853,7 @@ proc check_v3_target_nprocs { } { set src nprocs[pid].cc set f [open $src "w"] - puts $f "#include <bits/c++config.h>" + puts $f "#include <bits/c++config.h>" puts $f "#if defined(_GLIBCXX_USE_GET_NPROCS)" puts $f "#elif defined(_GLIBCXX_USE_PTHREADS_NUM_PROCESSORS_NP)" puts $f "#elif defined(_GLIBCXX_USE_SYSCTL_HW_NCPU)" @@ -1849,7 +1899,7 @@ proc check_v3_target_static_libstdcxx { } { set src static-maybe[pid].cc set f [open $src "w"] - puts $f "#include <iostream>" + puts $f "#include <iostream>" puts $f "int main() {" puts $f "int i(415);" puts $f "std::cout<< i << std::endl;" @@ -1883,46 +1933,46 @@ proc check_v3_target_little_endian { } { global tool if { ![info exists et_little_endian_target_name] } { - set et_little_endian_target_name "" + set et_little_endian_target_name "" } # If the target has changed since we set the cached value, clear it. set current_target [current_target_name] if { $current_target != $et_little_endian_target_name } { - verbose "check_v3_target_little_endian: `$et_little_endian_target_name'" 2 - set et_little_endian_target_name $current_target - if [info exists et_little_endian] { - verbose "check_v3_target_little_endian: removing cached result" 2 - unset et_little_endian - } + verbose "check_v3_target_little_endian: `$et_little_endian_target_name'" 2 + set et_little_endian_target_name $current_target + if [info exists et_little_endian] { + verbose "check_v3_target_little_endian: removing cached result" 2 + unset et_little_endian + } } if [info exists et_little_endian] { - verbose "check_v3_target_little_endian: using cached result" 2 + verbose "check_v3_target_little_endian: using cached result" 2 } else { - set et_little_endian 0 + set et_little_endian 0 - set src little_endian[pid].cc + set src little_endian[pid].cc - set f [open $src "w"] - puts $f "#if __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__" - puts $f "# error Not little endian" - puts $f "#endif" - close $f + set f [open $src "w"] + puts $f "#if __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__" + puts $f "# error Not little endian" + puts $f "#endif" + close $f - set cxxflags_saved $cxxflags - set cxxflags "$cxxflags $DEFAULT_CXXFLAGS -Werror" + set cxxflags_saved $cxxflags + set cxxflags "$cxxflags $DEFAULT_CXXFLAGS -Werror" - set lines [v3_target_compile $src /dev/null preprocess ""] - set cxxflags $cxxflags_saved - file delete $src + set lines [v3_target_compile $src /dev/null preprocess ""] + set cxxflags $cxxflags_saved + file delete $src - if [string match "" $lines] { - # No error message, preprocessing succeeded. - set et_little_endian 1 - } else { - verbose "check_v3_target_little_endian: compilation failed" 2 - } + if [string match "" $lines] { + # No error message, preprocessing succeeded. + set et_little_endian 1 + } else { + verbose "check_v3_target_little_endian: compilation failed" 2 + } } verbose "check_v3_target_little_endian: $et_little_endian" 2 return $et_little_endian @@ -2002,9 +2052,9 @@ proc check_effective_target_cxx11-abi { } { file delete $src if [string match "" $lines] { - # No error message, preprocessing succeeded. - verbose "check_v3_cxx11_abi: `1'" 2 - return 1 + # No error message, preprocessing succeeded. + verbose "check_v3_cxx11_abi: `1'" 2 + return 1 } verbose "check_v3_cxx11_abi: `0'" 2 diff --git a/libstdc++-v3/testsuite/util/testsuite_fs.h b/libstdc++-v3/testsuite/util/testsuite_fs.h index 38ebd4fb079..c18dae28fcc 100644 --- a/libstdc++-v3/testsuite/util/testsuite_fs.h +++ b/libstdc++-v3/testsuite/util/testsuite_fs.h @@ -22,7 +22,14 @@ #ifndef _TESTSUITE_FS_H #define _TESTSUITE_FS_H 1 +// Assume we want std::filesystem in C++17, unless USE_FILESYSTEM_TS defined: +#if __cplusplus >= 201703L && ! defined USE_FILESYSTEM_TS +#include <filesystem> +namespace test_fs = std::filesystem; +#else #include <experimental/filesystem> +namespace test_fs = std::experimental::filesystem; +#endif #include <fstream> #include <string> #include <cstdio> @@ -33,13 +40,14 @@ namespace __gnu_test { #define PATH_CHK(p1, p2, fn) \ if ( p1.fn() != p2.fn() ) \ - throw std::experimental::filesystem::filesystem_error( #fn, p1, p2, \ + throw test_fs::filesystem_error("comparing '" #fn "' failed", p1, p2, \ std::make_error_code(std::errc::invalid_argument) ) void - compare_paths(const std::experimental::filesystem::path& p1, - const std::experimental::filesystem::path& p2) + compare_paths(const test_fs::path& p1, + const test_fs::path& p2) { + PATH_CHK( p1, p2, native ); PATH_CHK( p1, p2, string ); PATH_CHK( p1, p2, empty ); PATH_CHK( p1, p2, has_root_path ); @@ -55,7 +63,7 @@ namespace __gnu_test auto d1 = std::distance(p1.begin(), p1.end()); auto d2 = std::distance(p2.begin(), p2.end()); if( d1 != d2 ) - throw std::experimental::filesystem::filesystem_error( + throw test_fs::filesystem_error( "distance(begin, end)", p1, p2, std::make_error_code(std::errc::invalid_argument) ); } @@ -67,15 +75,15 @@ namespace __gnu_test // This is NOT supposed to be a secure way to get a unique name! // We just need a path that doesn't exist for testing purposes. - std::experimental::filesystem::path + test_fs::path nonexistent_path() { - std::experimental::filesystem::path p; + test_fs::path p; #if defined(_GNU_SOURCE) || _XOPEN_SOURCE >= 500 || _POSIX_C_SOURCE >= 200112L - char tmp[] = "filesystem-ts-test.XXXXXX"; + char tmp[] = "filesystem-test.XXXXXX"; int fd = ::mkstemp(tmp); if (fd == -1) - throw std::experimental::filesystem::filesystem_error("mkstemp failed", + throw test_fs::filesystem_error("mkstemp failed", std::error_code(errno, std::generic_category())); ::unlink(tmp); ::close(fd); @@ -88,7 +96,7 @@ namespace __gnu_test #else std::sprintf(buf, #endif - "filesystem-ts-test.%d.%lu", counter++, (unsigned long) ::getpid()); + "filesystem-test.%d.%lu", counter++, (unsigned long) ::getpid()); p = buf; #endif return p; @@ -97,7 +105,7 @@ namespace __gnu_test // RAII helper to remove a file on scope exit. struct scoped_file { - using path_type = std::experimental::filesystem::path; + using path_type = test_fs::path; enum adopt_file_t { adopt_file }; diff --git a/libstdc++-v3/testsuite/util/testsuite_iterators.h b/libstdc++-v3/testsuite/util/testsuite_iterators.h index d61b2162c14..d6b550dd416 100644 --- a/libstdc++-v3/testsuite/util/testsuite_iterators.h +++ b/libstdc++-v3/testsuite/util/testsuite_iterators.h @@ -180,6 +180,11 @@ namespace __gnu_test #endif }; +#if __cplusplus >= 201103L + template<typename T, typename U> + void operator,(const T&, const output_iterator_wrapper<U>&) = delete; +#endif + /** * @brief input_iterator wrapper for pointer * @@ -270,6 +275,10 @@ namespace __gnu_test #endif }; +#if __cplusplus >= 201103L + template<typename T, typename U> + void operator,(const T&, const input_iterator_wrapper<U>&) = delete; +#endif /** * @brief forward_iterator wrapper for pointer |