diff options
Diffstat (limited to 'libstdc++-v3/testsuite')
31 files changed, 642 insertions, 91 deletions
diff --git a/libstdc++-v3/testsuite/20_util/duration/literals/range.cc b/libstdc++-v3/testsuite/20_util/duration/literals/range.cc index c0d1a6e5885..b5105dff38b 100644 --- a/libstdc++-v3/testsuite/20_util/duration/literals/range.cc +++ b/libstdc++-v3/testsuite/20_util/duration/literals/range.cc @@ -26,6 +26,6 @@ test01() // std::numeric_limits<int64_t>::max() == 9223372036854775807; auto h = 9223372036854775808h; - // { dg-error "cannot be represented" "" { target *-*-* } 892 } + // { dg-error "cannot be represented" "" { target *-*-* } 880 } } // { dg-prune-output "in constexpr expansion" } // needed for -O0 diff --git a/libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg1.cc b/libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg1.cc index 189e97bf984..17f74187098 100644 --- a/libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg1.cc +++ b/libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg1.cc @@ -30,4 +30,4 @@ void test01() test_type d; // { dg-error "required from here" } } -// { dg-error "rep cannot be a duration" "" { target *-*-* } 308 } +// { dg-error "rep cannot be a duration" "" { target *-*-* } 300 } diff --git a/libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg2.cc b/libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg2.cc index 501de5ee752..282a9dbdc85 100644 --- a/libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg2.cc +++ b/libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg2.cc @@ -31,5 +31,5 @@ void test01() test_type d; // { dg-error "required from here" } } -// { dg-error "must be a specialization of ratio" "" { target *-*-* } 309 } +// { dg-error "must be a specialization of ratio" "" { target *-*-* } 301 } // { dg-prune-output "not a member" } diff --git a/libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg3.cc b/libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg3.cc index a56bb96f5d0..c57f9d947a5 100644 --- a/libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg3.cc +++ b/libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg3.cc @@ -32,4 +32,4 @@ void test01() test_type d; // { dg-error "required from here" } } -// { dg-error "period must be positive" "" { target *-*-* } 311 } +// { dg-error "period must be positive" "" { target *-*-* } 303 } diff --git a/libstdc++-v3/testsuite/20_util/forward/c_neg.cc b/libstdc++-v3/testsuite/20_util/forward/c_neg.cc index c7830d7b2d4..d098164c0f7 100644 --- a/libstdc++-v3/testsuite/20_util/forward/c_neg.cc +++ b/libstdc++-v3/testsuite/20_util/forward/c_neg.cc @@ -17,7 +17,7 @@ // with this library; see the file COPYING3. If not see // <http://www.gnu.org/licenses/>. -// { dg-error "static assertion failed" "" { target *-*-* } 86 } +// { dg-error "static assertion failed" "" { target *-*-* } 87 } #include <list> diff --git a/libstdc++-v3/testsuite/20_util/forward/f_neg.cc b/libstdc++-v3/testsuite/20_util/forward/f_neg.cc index 7d073fe822b..0ca36d4b5a6 100644 --- a/libstdc++-v3/testsuite/20_util/forward/f_neg.cc +++ b/libstdc++-v3/testsuite/20_util/forward/f_neg.cc @@ -17,7 +17,7 @@ // with this library; see the file COPYING3. If not see // <http://www.gnu.org/licenses/>. -// { dg-error "static assertion failed" "" { target *-*-* } 86 } +// { dg-error "static assertion failed" "" { target *-*-* } 87 } #include <utility> 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 d80c1259c02..39d3e76ee82 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 @@ -180,6 +180,7 @@ void test12() std::uninitialized_default_construct(target, target+10); } catch (...) { } + free(target); VERIFY(ctor_count == 5); VERIFY(del_count == 5); throw_after = 0; @@ -198,6 +199,7 @@ void test13() std::uninitialized_value_construct(target, target+10); } catch (...) { } + free(target); VERIFY(ctor_count == 5); VERIFY(del_count == 5); throw_after = 0; @@ -216,6 +218,7 @@ void test14() std::uninitialized_default_construct_n(target, 10); } catch (...) { } + free(target); VERIFY(ctor_count == 5); VERIFY(del_count == 5); throw_after = 0; @@ -234,6 +237,7 @@ void test15() std::uninitialized_value_construct_n(target, 10); } catch (...) { } + free(target); VERIFY(ctor_count == 5); VERIFY(del_count == 5); throw_after = 0; @@ -254,6 +258,7 @@ void test16() std::uninitialized_move(source.begin(), source.end(), target); } catch (...) { } + free(target); VERIFY(ctor_count == 5); VERIFY(del_count == 5); throw_after = 0; @@ -273,6 +278,7 @@ void test17() std::uninitialized_move_n(source.begin(), 10, target); } catch (...) { } + free(target); VERIFY(ctor_count == 5); VERIFY(del_count == 5); throw_after = 0; diff --git a/libstdc++-v3/testsuite/20_util/variant/compile.cc b/libstdc++-v3/testsuite/20_util/variant/compile.cc index 06e8eb31ee8..e5f7538ba42 100644 --- a/libstdc++-v3/testsuite/20_util/variant/compile.cc +++ b/libstdc++-v3/testsuite/20_util/variant/compile.cc @@ -88,10 +88,12 @@ void copy_ctor() { static_assert(is_copy_constructible_v<variant<int, string>>, ""); static_assert(!is_copy_constructible_v<variant<AllDeleted, string>>, ""); + static_assert(is_trivially_copy_constructible_v<variant<int>>, ""); + static_assert(!is_trivially_copy_constructible_v<variant<std::string>>, ""); { variant<int> a; - static_assert(!noexcept(variant<int>(a)), ""); + static_assert(noexcept(variant<int>(a)), ""); } { variant<string> a; @@ -103,7 +105,7 @@ void copy_ctor() } { variant<int, char> a; - static_assert(!noexcept(variant<int, char>(a)), ""); + static_assert(noexcept(variant<int, char>(a)), ""); } } @@ -111,6 +113,8 @@ void move_ctor() { static_assert(is_move_constructible_v<variant<int, string>>, ""); static_assert(!is_move_constructible_v<variant<AllDeleted, string>>, ""); + static_assert(is_trivially_move_constructible_v<variant<int>>, ""); + static_assert(!is_trivially_move_constructible_v<variant<std::string>>, ""); static_assert(!noexcept(variant<int, Empty>(declval<variant<int, Empty>>())), ""); static_assert(noexcept(variant<int, DefaultNoexcept>(declval<variant<int, DefaultNoexcept>>())), ""); } @@ -148,13 +152,15 @@ void copy_assign() { static_assert(is_copy_assignable_v<variant<int, string>>, ""); static_assert(!is_copy_assignable_v<variant<AllDeleted, string>>, ""); + static_assert(is_trivially_copy_assignable_v<variant<int>>, ""); + static_assert(!is_trivially_copy_assignable_v<variant<string>>, ""); { variant<Empty> a; static_assert(!noexcept(a = a), ""); } { variant<DefaultNoexcept> a; - static_assert(!noexcept(a = a), ""); + static_assert(noexcept(a = a), ""); } } @@ -162,6 +168,8 @@ void move_assign() { static_assert(is_move_assignable_v<variant<int, string>>, ""); static_assert(!is_move_assignable_v<variant<AllDeleted, string>>, ""); + static_assert(is_trivially_move_assignable_v<variant<int>>, ""); + static_assert(!is_trivially_move_assignable_v<variant<string>>, ""); { variant<Empty> a; static_assert(!noexcept(a = std::move(a)), ""); @@ -454,3 +462,92 @@ void test_emplace() static_assert(!has_type_emplace<variant<AllDeleted>, AllDeleted>(0), ""); static_assert(!has_index_emplace<variant<AllDeleted>, 0>(0), ""); } + +void test_triviality() +{ +#define TEST_TEMPLATE(DT, CC, MC, CA, MA, CC_VAL, MC_VAL, CA_VAL, MA_VAL) \ + { \ + struct A \ + { \ + ~A() DT; \ + A(const A&) CC; \ + A(A&&) MC; \ + A& operator=(const A&) CA; \ + A& operator=(A&&) MA; \ + }; \ + static_assert(CC_VAL == is_trivially_copy_constructible_v<variant<A>>, ""); \ + static_assert(MC_VAL == is_trivially_move_constructible_v<variant<A>>, ""); \ + static_assert(CA_VAL == is_trivially_copy_assignable_v<variant<A>>, ""); \ + static_assert(MA_VAL == is_trivially_move_assignable_v<variant<A>>, ""); \ + } + TEST_TEMPLATE(=default, =default, =default, =default, =default, true, true, true, true) + TEST_TEMPLATE(=default, =default, =default, =default, {}, true, true, true, false) + TEST_TEMPLATE(=default, =default, =default, {}, =default, true, true, false, true) + TEST_TEMPLATE(=default, =default, =default, {}, {}, true, true, false, false) + TEST_TEMPLATE(=default, =default, {}, =default, =default, true, false, true, true) + TEST_TEMPLATE(=default, =default, {}, =default, {}, true, false, true, false) + TEST_TEMPLATE(=default, =default, {}, {}, =default, true, false, false, true) + TEST_TEMPLATE(=default, =default, {}, {}, {}, true, false, false, false) + TEST_TEMPLATE(=default, {}, =default, =default, =default, false, true, true, true) + TEST_TEMPLATE(=default, {}, =default, =default, {}, false, true, true, false) + TEST_TEMPLATE(=default, {}, =default, {}, =default, false, true, false, true) + TEST_TEMPLATE(=default, {}, =default, {}, {}, false, true, false, false) + TEST_TEMPLATE(=default, {}, {}, =default, =default, false, false, true, true) + TEST_TEMPLATE(=default, {}, {}, =default, {}, false, false, true, false) + TEST_TEMPLATE(=default, {}, {}, {}, =default, false, false, false, true) + TEST_TEMPLATE(=default, {}, {}, {}, {}, false, false, false, false) + TEST_TEMPLATE( {}, =default, =default, =default, =default, false, false, false, false) + TEST_TEMPLATE( {}, =default, =default, =default, {}, false, false, false, false) + TEST_TEMPLATE( {}, =default, =default, {}, =default, false, false, false, false) + TEST_TEMPLATE( {}, =default, =default, {}, {}, false, false, false, false) + TEST_TEMPLATE( {}, =default, {}, =default, =default, false, false, false, false) + TEST_TEMPLATE( {}, =default, {}, =default, {}, false, false, false, false) + TEST_TEMPLATE( {}, =default, {}, {}, =default, false, false, false, false) + TEST_TEMPLATE( {}, =default, {}, {}, {}, false, false, false, false) + TEST_TEMPLATE( {}, {}, =default, =default, =default, false, false, false, false) + TEST_TEMPLATE( {}, {}, =default, =default, {}, false, false, false, false) + TEST_TEMPLATE( {}, {}, =default, {}, =default, false, false, false, false) + TEST_TEMPLATE( {}, {}, =default, {}, {}, false, false, false, false) + TEST_TEMPLATE( {}, {}, {}, =default, =default, false, false, false, false) + TEST_TEMPLATE( {}, {}, {}, =default, {}, false, false, false, false) + TEST_TEMPLATE( {}, {}, {}, {}, =default, false, false, false, false) + TEST_TEMPLATE( {}, {}, {}, {}, {}, false, false, false, false) +#undef TEST_TEMPLATE + +#define TEST_TEMPLATE(CC, MC, CA, MA) \ + { \ + struct A \ + { \ + A(const A&) CC; \ + A(A&&) MC; \ + A& operator=(const A&) CA; \ + A& operator=(A&&) MA; \ + }; \ + static_assert(!is_trivially_copy_constructible_v<variant<AllDeleted, A>>, ""); \ + static_assert(!is_trivially_move_constructible_v<variant<AllDeleted, A>>, ""); \ + static_assert(!is_trivially_copy_assignable_v<variant<AllDeleted, A>>, ""); \ + static_assert(!is_trivially_move_assignable_v<variant<AllDeleted, A>>, ""); \ + } + TEST_TEMPLATE(=default, =default, =default, =default) + TEST_TEMPLATE(=default, =default, =default, {}) + TEST_TEMPLATE(=default, =default, {}, =default) + TEST_TEMPLATE(=default, =default, {}, {}) + TEST_TEMPLATE(=default, {}, =default, =default) + TEST_TEMPLATE(=default, {}, =default, {}) + TEST_TEMPLATE(=default, {}, {}, =default) + TEST_TEMPLATE(=default, {}, {}, {}) + TEST_TEMPLATE( {}, =default, =default, =default) + TEST_TEMPLATE( {}, =default, =default, {}) + TEST_TEMPLATE( {}, =default, {}, =default) + TEST_TEMPLATE( {}, =default, {}, {}) + TEST_TEMPLATE( {}, {}, =default, =default) + TEST_TEMPLATE( {}, {}, =default, {}) + TEST_TEMPLATE( {}, {}, {}, =default) + TEST_TEMPLATE( {}, {}, {}, {}) +#undef TEST_TEMPLATE + + static_assert(is_trivially_copy_constructible_v<variant<DefaultNoexcept, int, char, float, double>>, ""); + static_assert(is_trivially_move_constructible_v<variant<DefaultNoexcept, int, char, float, double>>, ""); + static_assert(is_trivially_copy_assignable_v<variant<DefaultNoexcept, int, char, float, double>>, ""); + static_assert(is_trivially_move_assignable_v<variant<DefaultNoexcept, int, char, float, double>>, ""); +} diff --git a/libstdc++-v3/testsuite/20_util/variant/deduction.cc b/libstdc++-v3/testsuite/20_util/variant/deduction.cc new file mode 100644 index 00000000000..33bc9d2a40e --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/variant/deduction.cc @@ -0,0 +1,39 @@ +// { dg-options "-std=gnu++17" } +// { dg-do compile { target c++1z } } + +// 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 <variant> + +template<typename T, typename U> struct require_same; +template<typename T> struct require_same<T, T> { using type = void; }; + +template<typename T, typename U> + typename require_same<T, U>::type + check_type(U&) { } + +void +test01() +{ + std::variant<int, double> x(3); + + std::variant copy = x; + check_type<decltype(x)>(copy); + std::variant move = std::move(x); + check_type<decltype(x)>(move); +} diff --git a/libstdc++-v3/testsuite/22_locale/locale/cons/5.cc b/libstdc++-v3/testsuite/22_locale/locale/cons/5.cc index 4c23c7f60e2..c0a18ce5d5c 100644 --- a/libstdc++-v3/testsuite/22_locale/locale/cons/5.cc +++ b/libstdc++-v3/testsuite/22_locale/locale/cons/5.cc @@ -37,34 +37,7 @@ void test04() #ifdef _GLIBCXX_HAVE_SETENV - const char* LANG_orig = getenv("LANG") ? strdup(getenv("LANG")) : ""; - const char* LC_ALL_orig = getenv("LC_ALL") ? strdup(getenv("LC_ALL")) : ""; - const char* LC_CTYPE_orig = - getenv("LC_CTYPE") ? strdup(getenv("LC_CTYPE")) : ""; - const char* LC_NUMERIC_orig = - getenv("LC_NUMERIC") ? strdup(getenv("LC_NUMERIC")) : ""; - const char* LC_TIME_orig = - getenv("LC_TIME") ? strdup(getenv("LC_TIME")) : ""; - const char* LC_COLLATE_orig = - getenv("LC_COLLATE") ? strdup(getenv("LC_COLLATE")) : ""; - const char* LC_MONETARY_orig = - getenv("LC_MONETARY") ? strdup(getenv("LC_MONETARY")) : ""; - const char* LC_MESSAGES_orig = - getenv("LC_MESSAGES") ? strdup(getenv("LC_MESSAGES")) : ""; -#if _GLIBCXX_NUM_CATEGORIES - const char* LC_PAPER_orig = - getenv("LC_PAPER") ? strdup(getenv("LC_PAPER")) : ""; - const char* LC_NAME_orig = - getenv("LC_NAME") ? strdup(getenv("LC_NAME")) : ""; - const char* LC_ADDRESS_orig = - getenv("LC_ADDRESS") ? strdup(getenv("LC_ADDRESS")) : ""; - const char* LC_TELEPHONE_orig = - getenv("LC_TELEPHONE") ? strdup(getenv("LC_TELEPHONE")) : ""; - const char* LC_MEASUREMENT_orig = - getenv("LC_MEASUREMENT") ? strdup(getenv("LC_MEASUREMENT")) : ""; - const char* LC_IDENTIFICATION_orig = - getenv("LC_IDENTIFICATION") ? strdup(getenv("LC_IDENTIFICATION")) : ""; -#endif + char* LANG_orig = strdup(getenv("LANG") ? getenv("LANG") : ""); // Check that a "POSIX" LC_ALL is equivalent to "C". if (!setenv("LC_ALL", "POSIX", 1)) @@ -91,12 +64,11 @@ void test04() VERIFY( loc.name() == "en_PH" ); } setenv("LC_ALL", "", 1); - setenv("LANG", LANG_orig ? LANG_orig : "", 1); - setenv("LC_COLLATE", LC_COLLATE_orig ? LC_COLLATE_orig : "", 1); + setenv("LANG", LANG_orig, 1); } // NB: LANG checks all LC_* macro settings. As such, all LC_* macros - // must be cleared for these tests, and then restored. + // must be cleared for these tests. setenv("LC_ALL", "", 1); setenv("LC_CTYPE", "", 1); setenv("LC_NUMERIC", "", 1); @@ -173,26 +145,9 @@ void test04() } #endif - // Restore the environment. - setenv("LANG", LANG_orig ? LANG_orig : "", 1); - setenv("LC_ALL", LC_ALL_orig ? LC_ALL_orig : "", 1); - setenv("LC_CTYPE", LC_CTYPE_orig ? LC_CTYPE_orig : "", 1); - setenv("LC_NUMERIC", LC_NUMERIC_orig ? LC_NUMERIC_orig : "", 1); - setenv("LC_TIME", LC_TIME_orig ? LC_TIME_orig : "", 1); - setenv("LC_COLLATE", LC_COLLATE_orig ? LC_COLLATE_orig : "", 1); - setenv("LC_MONETARY", LC_MONETARY_orig ? LC_MONETARY_orig : "", 1); - setenv("LC_MESSAGES", LC_MESSAGES_orig ? LC_MESSAGES_orig : "", 1); -#if _GLIBCXX_NUM_CATEGORIES - setenv("LC_PAPER", LC_PAPER_orig ? LC_PAPER_orig : "", 1); - setenv("LC_NAME", LC_NAME_orig ? LC_NAME_orig : "", 1); - setenv("LC_ADDRESS", LC_ADDRESS_orig ? LC_ADDRESS_orig : "", 1); - setenv("LC_TELEPHONE", LC_TELEPHONE_orig ? LC_TELEPHONE_orig : "", 1); - setenv("LC_MEASUREMENT", LC_MEASUREMENT_orig ? LC_MEASUREMENT_orig : "", 1); - setenv("LC_IDENTIFICATION", - LC_IDENTIFICATION_orig ? LC_IDENTIFICATION_orig : "", 1); -#endif + free(LANG_orig); -#endif +#endif // _GLIBCXX_HAVE_SETENV } int main() diff --git a/libstdc++-v3/testsuite/23_containers/list/allocator/default_init.cc b/libstdc++-v3/testsuite/23_containers/list/allocator/default_init.cc new file mode 100644 index 00000000000..0604e067252 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/allocator/default_init.cc @@ -0,0 +1,71 @@ +// 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 run { target c++11 } } +// { dg-options "-O0" } +// { dg-xfail-run-if "PR c++/65816" { *-*-* } } + +#include <list> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +#include <ext/aligned_buffer.h> + +using T = int; + +using __gnu_test::default_init_allocator; + +void test01() +{ + typedef default_init_allocator<T> alloc_type; + typedef std::list<T, alloc_type> test_type; + + __gnu_cxx::__aligned_buffer<test_type> buf; + __builtin_memset(buf._M_addr(), ~0, sizeof(test_type)); + + VERIFY( buf._M_ptr()->get_allocator().state != 0 ); + + test_type *tmp = ::new(buf._M_addr()) test_type(); + + VERIFY( tmp->get_allocator().state == 0 ); + + tmp->~test_type(); +} + +void test02() +{ + typedef default_init_allocator<T> alloc_type; + typedef std::list<T, alloc_type> test_type; + + __gnu_cxx::__aligned_buffer<test_type> buf; + __builtin_memset(buf._M_addr(), ~0, sizeof(test_type)); + + VERIFY( buf._M_ptr()->get_allocator().state != 0 ); + + test_type *tmp = ::new(buf._M_addr()) test_type; + + VERIFY( tmp->get_allocator().state == 0 ); + + tmp->~test_type(); +} + +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/sample/81221.cc b/libstdc++-v3/testsuite/25_algorithms/sample/81221.cc new file mode 100644 index 00000000000..28ec0e3152a --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/sample/81221.cc @@ -0,0 +1,22 @@ +// 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 { target c++1z } } +// { dg-require-parallel-mode "" } + +#include <algorithm> diff --git a/libstdc++-v3/testsuite/26_numerics/gcd/gcd_neg.cc b/libstdc++-v3/testsuite/26_numerics/gcd/gcd_neg.cc index d88f145d754..8c3494d7041 100644 --- a/libstdc++-v3/testsuite/26_numerics/gcd/gcd_neg.cc +++ b/libstdc++-v3/testsuite/26_numerics/gcd/gcd_neg.cc @@ -31,9 +31,9 @@ test01() std::gcd(0.1, 0.1); // { dg-error "from here" } } -// { dg-error "integers" "" { target *-*-* } 134 } -// { dg-error "integers" "" { target *-*-* } 135 } -// { dg-error "not bools" "" { target *-*-* } 136 } -// { dg-error "not bools" "" { target *-*-* } 137 } +// { dg-error "integers" "" { target *-*-* } 130 } +// { dg-error "integers" "" { target *-*-* } 131 } +// { dg-error "not bools" "" { target *-*-* } 132 } +// { dg-error "not bools" "" { target *-*-* } 133 } // { dg-prune-output "deleted function" } // { dg-prune-output "invalid operands" } diff --git a/libstdc++-v3/testsuite/26_numerics/lcm/lcm_neg.cc b/libstdc++-v3/testsuite/26_numerics/lcm/lcm_neg.cc index f2d82894531..abcac4f18c1 100644 --- a/libstdc++-v3/testsuite/26_numerics/lcm/lcm_neg.cc +++ b/libstdc++-v3/testsuite/26_numerics/lcm/lcm_neg.cc @@ -31,9 +31,9 @@ test01() std::lcm(0.1, 0.1); // { dg-error "from here" } } -// { dg-error "integers" "" { target *-*-* } 147 } -// { dg-error "integers" "" { target *-*-* } 148 } -// { dg-error "not bools" "" { target *-*-* } 149 } -// { dg-error "not bools" "" { target *-*-* } 150 } +// { dg-error "integers" "" { target *-*-* } 143 } +// { dg-error "integers" "" { target *-*-* } 144 } +// { dg-error "not bools" "" { target *-*-* } 145 } +// { dg-error "not bools" "" { target *-*-* } 146 } // { dg-prune-output "deleted function" } // { dg-prune-output "invalid operands" } diff --git a/libstdc++-v3/testsuite/26_numerics/random/pr60037-neg.cc b/libstdc++-v3/testsuite/26_numerics/random/pr60037-neg.cc index ad2cbc6e71b..22485222f28 100644 --- a/libstdc++-v3/testsuite/26_numerics/random/pr60037-neg.cc +++ b/libstdc++-v3/testsuite/26_numerics/random/pr60037-neg.cc @@ -9,6 +9,6 @@ std::__detail::_Adaptor<std::mt19937, unsigned long> aurng(urng); auto x = std::generate_canonical<std::size_t, std::numeric_limits<std::size_t>::digits>(urng); -// { dg-error "static assertion failed: template argument must be a floating point type" "" { target *-*-* } 160 } +// { dg-error "static assertion failed: template argument must be a floating point type" "" { target *-*-* } 156 } -// { dg-error "static assertion failed: template argument must be a floating point type" "" { target *-*-* } 3314 } +// { dg-error "static assertion failed: template argument must be a floating point type" "" { target *-*-* } 3311 } diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/81395.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/81395.cc new file mode 100644 index 00000000000..ea8dbc1259b --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/81395.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-require-fileio "" } + +// PR libstdc++/81395 + +#include <fstream> +#include <cstring> // for std::memset +#include <cstdio> // For BUFSIZ + +using std::memset; + +int main() +{ + { + std::filebuf fb; + fb.open("test.txt", std::ios::out); + char data[BUFSIZ]; + memset(data, 'A', sizeof(data)); + fb.sputn(data, sizeof(data)); + } + + std::filebuf fb; + fb.open("test.txt", std::ios::in|std::ios::out); + char buf[BUFSIZ]; + memset(buf, 0, sizeof(buf)); + fb.sgetn(buf, sizeof(buf)); + // Switch from reading to writing without seeking first: + fb.sputn("B", 1); + fb.pubsync(); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_fstream/53984.cc b/libstdc++-v3/testsuite/27_io/basic_fstream/53984.cc new file mode 100644 index 00000000000..e49d2b1ad1f --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_fstream/53984.cc @@ -0,0 +1,39 @@ +// 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-require-fileio "" } + +#include <fstream> +#include <testsuite_hooks.h> + +void +test01() +{ + std::ifstream in("."); + if (in) + { + int x; + in >> x; + VERIFY( in.bad() ); + } +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/sentry/char/53984.cc b/libstdc++-v3/testsuite/27_io/basic_istream/sentry/char/53984.cc new file mode 100644 index 00000000000..9c08c7236da --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/sentry/char/53984.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/>. + +#include <streambuf> +#include <istream> +#include <testsuite_hooks.h> + +struct SB : std::streambuf +{ + virtual int_type underflow() { throw 1; } +}; + +void +test01() +{ + SB sb; + std::istream is(&sb); + int i; + is >> i; + VERIFY( is.bad() ); +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/81381.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/81381.cc new file mode 100644 index 00000000000..865449d72ee --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/81381.cc @@ -0,0 +1,42 @@ +// 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 run { target c++11 } } + +// PR libstdc++/81381 + +#include <memory> +#include <sstream> +#include <testsuite_allocator.h> + +using Alloc = __gnu_test::uneq_allocator<char>; +using String = std::basic_string<char, std::char_traits<char>, Alloc>; + +struct SB : std::basic_stringbuf<char, std::char_traits<char>, Alloc> +{ + SB(const String& s) : basic_stringbuf(s) { } + + using basic_stringbuf::overflow; +}; + +int main() +{ + String s(Alloc(23)); + SB b(s); + b.overflow('a'); + VERIFY( b.str().get_allocator() == s.get_allocator() ); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringstream/assign/81338.cc b/libstdc++-v3/testsuite/27_io/basic_stringstream/assign/81338.cc new file mode 100644 index 00000000000..30370c0dd42 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringstream/assign/81338.cc @@ -0,0 +1,40 @@ +// 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 run { target c++11 } } + +#include <sstream> +#include <testsuite_hooks.h> + +void +test01() +{ + std::stringstream ss; + for (int i = 0; i < 100; ++i) + { + ss << 'a'; + VERIFY( static_cast<bool>(ss) ); + VERIFY( ss.str() == "a" ); + ss = std::stringstream(); + } +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/types/1.cc b/libstdc++-v3/testsuite/27_io/types/1.cc index 88f6ff868d7..0756f8a1709 100644 --- a/libstdc++-v3/testsuite/27_io/types/1.cc +++ b/libstdc++-v3/testsuite/27_io/types/1.cc @@ -15,6 +15,8 @@ // with this library; see the file COPYING3. If not see // <http://www.gnu.org/licenses/>. +// { dg-do compile { target c++14_down } } + // 27.4.2.1 - Types [lib.ios.types] #include <ios> @@ -27,9 +29,3 @@ void test01() typedef std::ios_base::streampos streampos_type; typedef std::ios_base::streamoff streamoff_type; } - -int main(void) -{ - test01(); - return 0; -} diff --git a/libstdc++-v3/testsuite/27_io/types/4.cc b/libstdc++-v3/testsuite/27_io/types/4.cc new file mode 100644 index 00000000000..ee1a77736ce --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/types/4.cc @@ -0,0 +1,29 @@ +// 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 { target c++1z } } + +// In C++17 these names are not reserved by the library. +#define io_state 1 +#define open_mode 2 +#define seek_dir 3 +#define stossc 4 +#include <streambuf> + +template class std::basic_streambuf<char>; +template class std::basic_streambuf<wchar_t>; diff --git a/libstdc++-v3/testsuite/30_threads/scoped_lock/cons/1.cc b/libstdc++-v3/testsuite/30_threads/scoped_lock/cons/1.cc index 9f1b48c809a..e420ab08378 100644 --- a/libstdc++-v3/testsuite/30_threads/scoped_lock/cons/1.cc +++ b/libstdc++-v3/testsuite/30_threads/scoped_lock/cons/1.cc @@ -79,7 +79,7 @@ void test01() try { - std::scoped_lock<BasicLockable> l(m, std::adopt_lock); + std::scoped_lock<BasicLockable> l(std::adopt_lock, m); } catch (...) { @@ -113,7 +113,7 @@ void test02() try { - std::scoped_lock<Lockable<1>, Lockable<2>> l(m1, m2, std::adopt_lock); + std::scoped_lock<Lockable<1>, Lockable<2>> l(std::adopt_lock, m1, m2); VERIFY( m1.m.locked ); VERIFY( m2.m.locked ); } diff --git a/libstdc++-v3/testsuite/30_threads/scoped_lock/cons/deduction.cc b/libstdc++-v3/testsuite/30_threads/scoped_lock/cons/deduction.cc index 399de7a5ae6..7d4f5bfc386 100644 --- a/libstdc++-v3/testsuite/30_threads/scoped_lock/cons/deduction.cc +++ b/libstdc++-v3/testsuite/30_threads/scoped_lock/cons/deduction.cc @@ -51,3 +51,28 @@ test01() std::scoped_lock l2(m2, m3); check_type<std::scoped_lock<Lockable, std::mutex>>(l2); } + +void +test02() +{ + std::scoped_lock l0(std::adopt_lock); + check_type<std::scoped_lock<>>(l0); + + struct BasicLockable { + void lock() { } + void unlock() { } + } m1; + + std::scoped_lock l1(std::adopt_lock, m1); + check_type<std::scoped_lock<BasicLockable>>(l1); + + struct Lockable { + void lock() { } + void unlock() { } + bool try_lock() { return true; } + } m2; + + std::mutex m3; + std::scoped_lock l2(std::adopt_lock, m2, m3); + check_type<std::scoped_lock<Lockable, std::mutex>>(l2); +} diff --git a/libstdc++-v3/testsuite/30_threads/scoped_lock/requirements/typedefs.cc b/libstdc++-v3/testsuite/30_threads/scoped_lock/requirements/typedefs.cc index 55756d87262..0a8903ebaab 100644 --- a/libstdc++-v3/testsuite/30_threads/scoped_lock/requirements/typedefs.cc +++ b/libstdc++-v3/testsuite/30_threads/scoped_lock/requirements/typedefs.cc @@ -25,6 +25,12 @@ #include <mutex> +#ifndef __cpp_lib_scoped_lock +# error "Feature-test macro for scoped_lock missing" +#elif __cpp_lib_scoped_lock != 201707 +# error "Feature-test macro for scoped_lock has wrong value" +#endif + void test01() { // Check for required typedefs diff --git a/libstdc++-v3/testsuite/abi/pr42230.cc b/libstdc++-v3/testsuite/abi/pr42230.cc index 2a338995336..48156e4ba18 100644 --- a/libstdc++-v3/testsuite/abi/pr42230.cc +++ b/libstdc++-v3/testsuite/abi/pr42230.cc @@ -3,6 +3,7 @@ #include <cxxabi.h> #include <cassert> #include <cstddef> +#include <cstdlib> int main() { @@ -12,5 +13,6 @@ int main() char* ret = abi::__cxa_demangle("e", 0, &length, &cc); assert( (cc < 0 && !ret) || (ret && length) ); + std::free(ret); return 0; } diff --git a/libstdc++-v3/testsuite/performance/23_containers/insert/81476.cc b/libstdc++-v3/testsuite/performance/23_containers/insert/81476.cc new file mode 100644 index 00000000000..2b76469ae11 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/23_containers/insert/81476.cc @@ -0,0 +1,86 @@ +// Copyright (C) 2012-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 run { target c++11 } } + +#include <random> +#include <vector> +#include <testsuite_hooks.h> +#include <testsuite_performance.h> + +int main() +{ + using namespace __gnu_test; + + std::default_random_engine eng; + std::uniform_int_distribution<unsigned> r(0, 127); + + time_counter time; + resource_counter resource; + + std::vector<std::vector<char>> vecs(10000); + for (auto& v : vecs) + { + v.resize(1000); + for (auto& c : v) + c = r(eng); + } + + start_counters(time, resource); + std::vector<char> res; + for (auto& v : vecs) + res.insert(res.begin(), v.begin(), v.end()); + stop_counters(time, resource); + report_performance(__FILE__, "insert pointers", time, resource); + + struct input_iterator : std::vector<char>::iterator + { + using iterator_category = std::input_iterator_tag; + using base = std::vector<char>::iterator; + + input_iterator(base it) : base(it) { } + }; + + start_counters(time, resource); + std::vector<char> res2; + for (auto& v : vecs) + { + auto begin = input_iterator(v.begin()); + auto end = input_iterator(v.end()); + res2.insert(res2.begin(), begin, end); + } + stop_counters(time, resource); + report_performance(__FILE__, "insert input iterators", time, resource); + + start_counters(time, resource); + std::vector<char> res3; + for (auto rev = vecs.rbegin(); rev != vecs.rend(); ++rev) + res3.insert(res3.end(), rev->begin(), rev->end()); + stop_counters(time, resource); + report_performance(__FILE__, "insert pointers end", time, resource); + + start_counters(time, resource); + std::vector<char> res4; + for (auto rev = vecs.rbegin(); rev != vecs.rend(); ++rev) + res4.insert(res4.end(), rev->begin(), rev->end()); + stop_counters(time, resource); + report_performance(__FILE__, "insert input iterators end", time, resource); + + VERIFY(res2 == res); + VERIFY(res3 == res); + VERIFY(res4 == res); +} diff --git a/libstdc++-v3/testsuite/util/testsuite_abi.cc b/libstdc++-v3/testsuite/util/testsuite_abi.cc index 4d7f4ca3a65..d18429a55b2 100644 --- a/libstdc++-v3/testsuite/util/testsuite_abi.cc +++ b/libstdc++-v3/testsuite/util/testsuite_abi.cc @@ -590,21 +590,26 @@ create_symbols(const char* file) } -const char* +std::string demangle(const std::string& mangled) { - const char* name; + std::string name; if (mangled[0] != '_' || mangled[1] != 'Z') { // This is not a mangled symbol, thus has "C" linkage. - name = mangled.c_str(); + name = mangled; } else { // Use __cxa_demangle to demangle. int status = 0; - name = abi::__cxa_demangle(mangled.c_str(), 0, 0, &status); - if (!name) + char* ptr = abi::__cxa_demangle(mangled.c_str(), 0, 0, &status); + if (ptr) + { + name = ptr; + free(ptr); + } + else { switch (status) { diff --git a/libstdc++-v3/testsuite/util/testsuite_abi.h b/libstdc++-v3/testsuite/util/testsuite_abi.h index 8275b23e162..77c5656177f 100644 --- a/libstdc++-v3/testsuite/util/testsuite_abi.h +++ b/libstdc++-v3/testsuite/util/testsuite_abi.h @@ -94,5 +94,5 @@ compare_symbols(const char* baseline_file, const char* test_file, bool verb); symbols create_symbols(const char* file); -const char* +std::string demangle(const std::string& mangled); diff --git a/libstdc++-v3/testsuite/util/testsuite_hooks.cc b/libstdc++-v3/testsuite/util/testsuite_hooks.cc index d1063e3d8d7..74e755dfe28 100644 --- a/libstdc++-v3/testsuite/util/testsuite_hooks.cc +++ b/libstdc++-v3/testsuite/util/testsuite_hooks.cc @@ -131,8 +131,11 @@ namespace __gnu_test verify_demangle(const char* mangled, const char* wanted) { int status = 0; - const char* s = abi::__cxa_demangle(mangled, 0, 0, &status); - if (!s) + const char* s = 0; + char* demangled = abi::__cxa_demangle(mangled, 0, 0, &status); + if (demangled) + s = demangled; + else { switch (status) { @@ -156,6 +159,7 @@ namespace __gnu_test std::string w(wanted); if (w != s) std::__throw_runtime_error(s); + free(demangled); } void diff --git a/libstdc++-v3/testsuite/util/testsuite_iterators.h b/libstdc++-v3/testsuite/util/testsuite_iterators.h index 6771ae2cea6..d61b2162c14 100644 --- a/libstdc++-v3/testsuite/util/testsuite_iterators.h +++ b/libstdc++-v3/testsuite/util/testsuite_iterators.h @@ -539,14 +539,14 @@ namespace __gnu_test struct test_container { typename ItType<T>::ContainerType bounds; - test_container(T* _first, T* _last):bounds(_first, _last) + test_container(T* _first, T* _last) : bounds(_first, _last) { } #if __cplusplus >= 201103L - template<std::size_t N> - explicit - test_container(T (&arr)[N]) : test_container(arr, arr+N) - { } + template<std::size_t N> + explicit + test_container(T (&arr)[N]) : test_container(arr, arr+N) + { } #endif ItType<T> @@ -574,6 +574,6 @@ namespace __gnu_test ItType<T> end() { return it(bounds.last); } - }; + }; } #endif |