diff options
Diffstat (limited to 'libstdc++-v3/testsuite/23_containers')
22 files changed, 643 insertions, 54 deletions
diff --git a/libstdc++-v3/testsuite/23_containers/deque/capacity/max_size.cc b/libstdc++-v3/testsuite/23_containers/deque/capacity/max_size.cc new file mode 100644 index 00000000000..1a38c4ed698 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/capacity/max_size.cc @@ -0,0 +1,146 @@ +// Copyright (C) 2018 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 } + +#include <deque> +#include <stdexcept> +#include <limits> +#include <testsuite_hooks.h> + +typedef std::deque<char> test_type; + +typedef test_type::size_type size_type; +typedef test_type::difference_type difference_type; + +const difference_type diffmax = std::numeric_limits<difference_type>::max(); + +void +test01() +{ + test_type v; + VERIFY( v.max_size() <= diffmax ); +} + +void +test02() +{ + size_type n = size_type(diffmax) + 1; + VERIFY( n > test_type().max_size() ); + + try { + test_type v(n); + VERIFY( false ); + } catch (const std::length_error&) { } + + try { + test_type v(n, 'x'); + VERIFY( false ); + } catch (const std::length_error&) { } + + try { + test_type v(n, 'x', test_type::allocator_type()); + VERIFY( false ); + } catch (const std::length_error&) { } +} + +#ifdef __GLIBCXX_TYPE_INT_N_0 +template<typename T, typename U, bool = (sizeof(T) > sizeof(long long))> + struct Base_ + { + typedef T difference_type; + typedef U size_type; + }; + +template<typename T, typename U> + struct Base_<T, U, false> + { + typedef long long difference_type; + typedef unsigned long long size_type; + }; + +typedef Base_<__GLIBCXX_TYPE_INT_N_0, unsigned __GLIBCXX_TYPE_INT_N_0> Base; +#else +struct Base +{ + typedef long long difference_type; + typedef unsigned long long size_type; +}; +#endif + +// An iterator with a difference_type larger than ptrdiff_t +struct Iter : Base +{ + typedef std::random_access_iterator_tag iterator_category; + typedef char value_type; + typedef const char* pointer; + typedef const char& reference; + using Base::difference_type; + + Iter() : n(0) { } + Iter(size_type n) : n(n) { } + + reference operator*() const { return value; } + pointer operator->() const { return &value; } + + Iter& operator++() { ++n; return *this; } + Iter operator++(int) { Iter tmp(*this); ++n; return tmp; } + Iter& operator--() { --n; return *this; } + Iter operator--(int) { Iter tmp(*this); --n; return tmp; } + + Iter& operator+=(difference_type d) { n += d; return *this; } + Iter& operator-=(difference_type d) { n -= d; return *this; } + + difference_type operator-(const Iter& rhs) const { return n - rhs.n; } + + reference operator[](difference_type d) const { return value; } + + bool operator==(const Iter& rhs) const { return n == rhs.n; } + bool operator!=(const Iter& rhs) const { return n != rhs.n; } + bool operator<(const Iter& rhs) const { return n < rhs.n; } + bool operator>(const Iter& rhs) const { return n > rhs.n; } + bool operator<=(const Iter& rhs) const { return n <= rhs.n; } + bool operator>=(const Iter& rhs) const { return n >= rhs.n; } + +private: + size_type n; + static const char value = 'x'; +}; + +Iter operator+(Iter i, Iter::difference_type n) { return i += n; } +Iter operator+(Iter::difference_type n, Iter i) { return i += n; } +Iter operator-(Iter::difference_type n, Iter i) { return i -= n; } + +void +test03() +{ + Iter first, last(Iter::size_type(diffmax) + 1); + VERIFY( std::distance(first, last) > test_type().max_size() ); + + try { + test_type vec(first, last); + VERIFY(false); + } catch (const std::length_error&) { } +} + +int +main() +{ + test01(); + test02(); + test03(); +} diff --git a/libstdc++-v3/testsuite/23_containers/deque/modifiers/assign/1.cc b/libstdc++-v3/testsuite/23_containers/deque/modifiers/assign/1.cc index fbab09b9ba2..a6668f7c199 100644 --- a/libstdc++-v3/testsuite/23_containers/deque/modifiers/assign/1.cc +++ b/libstdc++-v3/testsuite/23_containers/deque/modifiers/assign/1.cc @@ -27,7 +27,7 @@ int main() { std::deque<int> d; - int array[] { 0, 1, 2 }; + int array[] = { 0, 1, 2 }; input_iterator_seq seq(array, array + 3); d.assign(seq.begin(), seq.end()); diff --git a/libstdc++-v3/testsuite/23_containers/deque/types/pmr_typedefs_debug.cc b/libstdc++-v3/testsuite/23_containers/deque/types/pmr_typedefs_debug.cc new file mode 100644 index 00000000000..85c725ad535 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/types/pmr_typedefs_debug.cc @@ -0,0 +1,25 @@ +// Copyright (C) 2018 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 -D_GLIBCXX_DEBUG" } +// { dg-do compile { target c++17 } } + +#include <debug/deque> +static_assert(std::is_same_v< + std::pmr::deque<int>, + __gnu_debug::deque<int, std::pmr::polymorphic_allocator<int>> + >); diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/pmr_typedefs_debug.cc b/libstdc++-v3/testsuite/23_containers/forward_list/pmr_typedefs_debug.cc new file mode 100644 index 00000000000..410ed82deed --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/pmr_typedefs_debug.cc @@ -0,0 +1,25 @@ +// Copyright (C) 2018 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 -D_GLIBCXX_DEBUG" } +// { dg-do compile { target c++17 } } + +#include <debug/forward_list> +static_assert(std::is_same_v< + std::pmr::forward_list<int>, + __gnu_debug::forward_list<int, std::pmr::polymorphic_allocator<int>> + >); diff --git a/libstdc++-v3/testsuite/23_containers/list/68222_neg.cc b/libstdc++-v3/testsuite/23_containers/list/68222_neg.cc new file mode 100644 index 00000000000..cd33762e01a --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/68222_neg.cc @@ -0,0 +1,37 @@ +// Copyright (C) 2018 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 <list> + +void +test01() +{ + // A list of int. + const std::list<int> nums = { 1, 2, 3, 4 }; + + // Grab the iterator type. + using list_itr_type = decltype( std::begin( nums ) ); + + // Confirm cend returns the same type. + static_assert( std::is_same< decltype( std::end( nums ) ), list_itr_type >::value, "" ); + + // The list's iterator type provides a well-formed non-member operator-() with valid return type (long int) + using substraction_type + = decltype( std::declval<list_itr_type>() - std::declval<list_itr_type>() ); // { dg-error "no match for 'operator-'" } +} diff --git a/libstdc++-v3/testsuite/23_containers/list/modifiers/assign/1.cc b/libstdc++-v3/testsuite/23_containers/list/modifiers/assign/1.cc index c5fde47059a..f4d32883328 100644 --- a/libstdc++-v3/testsuite/23_containers/list/modifiers/assign/1.cc +++ b/libstdc++-v3/testsuite/23_containers/list/modifiers/assign/1.cc @@ -27,7 +27,7 @@ int main() { std::list<int> l; - int array[] { 0, 1, 2 }; + int array[] = { 0, 1, 2 }; input_iterator_seq seq(array, array + 3); l.assign(seq.begin(), seq.end()); diff --git a/libstdc++-v3/testsuite/23_containers/list/pmr_typedefs_debug.cc b/libstdc++-v3/testsuite/23_containers/list/pmr_typedefs_debug.cc new file mode 100644 index 00000000000..671c12e43d1 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/pmr_typedefs_debug.cc @@ -0,0 +1,25 @@ +// Copyright (C) 2018 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 -D_GLIBCXX_DEBUG" } +// { dg-do compile { target c++17 } } + +#include <debug/list> +static_assert(std::is_same_v< + std::pmr::list<int>, + __gnu_debug::list<int, std::pmr::polymorphic_allocator<int>> + >); diff --git a/libstdc++-v3/testsuite/23_containers/map/pmr_typedefs_debug.cc b/libstdc++-v3/testsuite/23_containers/map/pmr_typedefs_debug.cc new file mode 100644 index 00000000000..e3978a1ec53 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/pmr_typedefs_debug.cc @@ -0,0 +1,26 @@ +// Copyright (C) 2018 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 -D_GLIBCXX_DEBUG" } +// { dg-do compile { target c++17 } } + +#include <debug/map> +static_assert(std::is_same_v< + std::pmr::map<int, int>, + __gnu_debug::map<int, int, std::less<int>, + std::pmr::polymorphic_allocator<std::pair<const int, int>>> + >); diff --git a/libstdc++-v3/testsuite/23_containers/multimap/pmr_typedefs_debug.cc b/libstdc++-v3/testsuite/23_containers/multimap/pmr_typedefs_debug.cc new file mode 100644 index 00000000000..cbd4d95176a --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/pmr_typedefs_debug.cc @@ -0,0 +1,26 @@ +// Copyright (C) 2018 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 -D_GLIBCXX_DEBUG" } +// { dg-do compile { target c++17 } } + +#include <debug/map> +static_assert(std::is_same_v< + std::pmr::multimap<int, int>, + __gnu_debug::multimap<int, int, std::less<int>, + std::pmr::polymorphic_allocator<std::pair<const int, int>>> + >); diff --git a/libstdc++-v3/testsuite/23_containers/multiset/pmr_typedefs_debug.cc b/libstdc++-v3/testsuite/23_containers/multiset/pmr_typedefs_debug.cc new file mode 100644 index 00000000000..d8ff08d04b5 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multiset/pmr_typedefs_debug.cc @@ -0,0 +1,26 @@ +// Copyright (C) 2018 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 -D_GLIBCXX_DEBUG" } +// { dg-do compile { target c++17 } } + +#include <debug/set> +static_assert(std::is_same_v< + std::pmr::multiset<int>, + __gnu_debug::multiset<int, std::less<int>, + std::pmr::polymorphic_allocator<int>> + >); diff --git a/libstdc++-v3/testsuite/23_containers/set/pmr_typedefs_debug.cc b/libstdc++-v3/testsuite/23_containers/set/pmr_typedefs_debug.cc new file mode 100644 index 00000000000..f44f68a49a4 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/set/pmr_typedefs_debug.cc @@ -0,0 +1,26 @@ +// Copyright (C) 2018 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 -D_GLIBCXX_DEBUG" } +// { dg-do compile { target c++17 } } + +#include <debug/set> +static_assert(std::is_same_v< + std::pmr::set<int>, + __gnu_debug::set<int, std::less<int>, + std::pmr::polymorphic_allocator<int>> + >); diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/pmr_typedefs_debug.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/pmr_typedefs_debug.cc new file mode 100644 index 00000000000..2c423bc79e2 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_map/pmr_typedefs_debug.cc @@ -0,0 +1,26 @@ +// Copyright (C) 2018 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 -D_GLIBCXX_DEBUG" } +// { dg-do compile { target c++17 } } + +#include <debug/unordered_map> +static_assert(std::is_same_v< + std::pmr::unordered_map<int, int>, + __gnu_debug::unordered_map<int, int, std::hash<int>, std::equal_to<int>, + std::pmr::polymorphic_allocator<std::pair<const int, int>>> + >); diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multimap/pmr_typedefs_debug.cc b/libstdc++-v3/testsuite/23_containers/unordered_multimap/pmr_typedefs_debug.cc new file mode 100644 index 00000000000..30ae2a732b6 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multimap/pmr_typedefs_debug.cc @@ -0,0 +1,27 @@ +// Copyright (C) 2018 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 -D_GLIBCXX_DEBUG" } +// { dg-do compile { target c++17 } } + +#include <debug/unordered_map> +static_assert(std::is_same_v< + std::pmr::unordered_multimap<int, int>, + __gnu_debug::unordered_multimap<int, int, std::hash<int>, + std::equal_to<int>, + std::pmr::polymorphic_allocator<std::pair<const int, int>>> + >); diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multiset/pmr_typedefs_debug.cc b/libstdc++-v3/testsuite/23_containers/unordered_multiset/pmr_typedefs_debug.cc new file mode 100644 index 00000000000..5f0ed27a1d0 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multiset/pmr_typedefs_debug.cc @@ -0,0 +1,26 @@ +// Copyright (C) 2018 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 -D_GLIBCXX_DEBUG" } +// { dg-do compile { target c++17 } } + +#include <debug/unordered_set> +static_assert(std::is_same_v< + std::pmr::unordered_multiset<int>, + __gnu_debug::unordered_multiset<int, std::hash<int>, std::equal_to<int>, + std::pmr::polymorphic_allocator<int>> + >); diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/debug/debug_functions.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/debug/debug_functions.cc index 9fb12edbe6e..1d45e74782d 100644 --- a/libstdc++-v3/testsuite/23_containers/unordered_set/debug/debug_functions.cc +++ b/libstdc++-v3/testsuite/23_containers/unordered_set/debug/debug_functions.cc @@ -21,31 +21,6 @@ #include <unordered_set> #include <testsuite_hooks.h> -void test01() -{ - using namespace __gnu_debug; - - std::unordered_set<int> u = { 0, 1, 2 }; - VERIFY( __check_dereferenceable(u.begin()) ); - auto it = u.begin(); - VERIFY( __check_dereferenceable(it) ); - - VERIFY( __check_dereferenceable(u.cbegin()) ); - auto cit = u.begin(); - VERIFY( __check_dereferenceable(cit) ); - - VERIFY( !__check_dereferenceable(u.end()) ); - it = u.end(); - VERIFY( !__check_dereferenceable(it) ); - - auto bucket = u.bucket(0); - VERIFY( __check_dereferenceable(u.begin(bucket)) ); - auto lit = u.begin(bucket); - VERIFY( __check_dereferenceable(lit) ); - - VERIFY( !__check_dereferenceable(u.end(bucket)) ); -} - void test02() { using namespace __gnu_debug; @@ -84,7 +59,6 @@ void test02() int main() { - test01(); test02(); return 0; } diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/pmr_typedefs_debug.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/pmr_typedefs_debug.cc new file mode 100644 index 00000000000..73ad1e0f01f --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_set/pmr_typedefs_debug.cc @@ -0,0 +1,26 @@ +// Copyright (C) 2018 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 -D_GLIBCXX_DEBUG" } +// { dg-do compile { target c++17 } } + +#include <debug/unordered_set> +static_assert(std::is_same_v< + std::pmr::unordered_set<int>, + __gnu_debug::unordered_set<int, std::hash<int>, std::equal_to<int>, + std::pmr::polymorphic_allocator<int>> + >); diff --git a/libstdc++-v3/testsuite/23_containers/vector/bool/modifiers/assign/1.cc b/libstdc++-v3/testsuite/23_containers/vector/bool/modifiers/assign/1.cc index 833201b39a3..06fb2ab2d03 100644 --- a/libstdc++-v3/testsuite/23_containers/vector/bool/modifiers/assign/1.cc +++ b/libstdc++-v3/testsuite/23_containers/vector/bool/modifiers/assign/1.cc @@ -27,7 +27,7 @@ void test01() std::vector<bool> bv; - bool array[] { false, true, true }; + bool array[] = { false, true, true }; input_iterator_seq seq(array, array + 3); bv.assign(seq.begin(), seq.end()); diff --git a/libstdc++-v3/testsuite/23_containers/vector/capacity/max_size.cc b/libstdc++-v3/testsuite/23_containers/vector/capacity/max_size.cc new file mode 100644 index 00000000000..34d3c4ab96e --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/capacity/max_size.cc @@ -0,0 +1,146 @@ +// Copyright (C) 2018 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 } + +#include <vector> +#include <stdexcept> +#include <limits> +#include <testsuite_hooks.h> + +typedef std::vector<char> test_type; + +typedef test_type::size_type size_type; +typedef test_type::difference_type difference_type; + +const difference_type diffmax = std::numeric_limits<difference_type>::max(); + +void +test01() +{ + test_type v; + VERIFY( v.max_size() <= diffmax ); +} + +void +test02() +{ + size_type n = size_type(diffmax) + 1; + VERIFY( n > test_type().max_size() ); + + try { + test_type v(n); + VERIFY( false ); + } catch (const std::length_error&) { } + + try { + test_type v(n, 'x'); + VERIFY( false ); + } catch (const std::length_error&) { } + + try { + test_type v(n, 'x', test_type::allocator_type()); + VERIFY( false ); + } catch (const std::length_error&) { } +} + +#ifdef __GLIBCXX_TYPE_INT_N_0 +template<typename T, typename U, bool = (sizeof(T) > sizeof(long long))> + struct Base_ + { + typedef T difference_type; + typedef U size_type; + }; + +template<typename T, typename U> + struct Base_<T, U, false> + { + typedef long long difference_type; + typedef unsigned long long size_type; + }; + +typedef Base_<__GLIBCXX_TYPE_INT_N_0, unsigned __GLIBCXX_TYPE_INT_N_0> Base; +#else +struct Base +{ + typedef long long difference_type; + typedef unsigned long long size_type; +}; +#endif + +// An iterator with a difference_type larger than ptrdiff_t +struct Iter : Base +{ + typedef std::random_access_iterator_tag iterator_category; + typedef char value_type; + typedef const char* pointer; + typedef const char& reference; + using Base::difference_type; + + Iter() : n(0) { } + Iter(size_type n) : n(n) { } + + reference operator*() const { return value; } + pointer operator->() const { return &value; } + + Iter& operator++() { ++n; return *this; } + Iter operator++(int) { Iter tmp(*this); ++n; return tmp; } + Iter& operator--() { --n; return *this; } + Iter operator--(int) { Iter tmp(*this); --n; return tmp; } + + Iter& operator+=(difference_type d) { n += d; return *this; } + Iter& operator-=(difference_type d) { n -= d; return *this; } + + difference_type operator-(const Iter& rhs) const { return n - rhs.n; } + + reference operator[](difference_type d) const { return value; } + + bool operator==(const Iter& rhs) const { return n == rhs.n; } + bool operator!=(const Iter& rhs) const { return n != rhs.n; } + bool operator<(const Iter& rhs) const { return n < rhs.n; } + bool operator>(const Iter& rhs) const { return n > rhs.n; } + bool operator<=(const Iter& rhs) const { return n <= rhs.n; } + bool operator>=(const Iter& rhs) const { return n >= rhs.n; } + +private: + size_type n; + static const char value = 'x'; +}; + +Iter operator+(Iter i, Iter::difference_type n) { return i += n; } +Iter operator+(Iter::difference_type n, Iter i) { return i += n; } +Iter operator-(Iter::difference_type n, Iter i) { return i -= n; } + +void +test03() +{ + Iter first, last(Iter::size_type(diffmax) + 1); + VERIFY( std::distance(first, last) > test_type().max_size() ); + + try { + test_type vec(first, last); + VERIFY(false); + } catch (const std::length_error&) { } +} + +int +main() +{ + test01(); + test02(); + test03(); +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/cons/destructible_debug_neg.cc b/libstdc++-v3/testsuite/23_containers/vector/cons/destructible_debug_neg.cc index 5127f5105f4..587c67fe936 100644 --- a/libstdc++-v3/testsuite/23_containers/vector/cons/destructible_debug_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/vector/cons/destructible_debug_neg.cc @@ -45,4 +45,4 @@ test02() // { dg-error "value type is destructible" "" { target *-*-* } 0 } // In Debug Mode the "required from here" errors come from <debug/vector> -// { dg-error "required from here" "" { target *-*-* } 155 } +// { dg-error "required from here" "" { target *-*-* } 163 } diff --git a/libstdc++-v3/testsuite/23_containers/vector/debug/debug_functions.cc b/libstdc++-v3/testsuite/23_containers/vector/debug/debug_functions.cc index ea683eeb776..acbd0d110c0 100644 --- a/libstdc++-v3/testsuite/23_containers/vector/debug/debug_functions.cc +++ b/libstdc++-v3/testsuite/23_containers/vector/debug/debug_functions.cc @@ -20,28 +20,6 @@ #include <vector> #include <testsuite_hooks.h> -void test01() -{ - using namespace __gnu_debug; - - std::vector<int> v1(3, 1); - VERIFY( __check_dereferenceable(v1.begin()) ); - std::vector<int>::iterator it = v1.begin(); - VERIFY( __check_dereferenceable(it) ); - - VERIFY( !__check_dereferenceable(v1.end()) ); - it = v1.end(); - VERIFY( !__check_dereferenceable(it) ); - - const volatile int* pi = 0; - VERIFY( !__check_dereferenceable(pi) ); - - int i; - pi = &i; - - VERIFY( __check_dereferenceable(pi) ); -} - void test02() { using namespace __gnu_debug; @@ -67,7 +45,6 @@ void test02() int main() { - test01(); test02(); return 0; } diff --git a/libstdc++-v3/testsuite/23_containers/vector/modifiers/assign/1.cc b/libstdc++-v3/testsuite/23_containers/vector/modifiers/assign/1.cc index ca7b125e7ca..001f204c93b 100644 --- a/libstdc++-v3/testsuite/23_containers/vector/modifiers/assign/1.cc +++ b/libstdc++-v3/testsuite/23_containers/vector/modifiers/assign/1.cc @@ -27,7 +27,7 @@ void test01() std::vector<int> v; - int array[] { 0, 1, 2 }; + int array[] = { 0, 1, 2 }; input_iterator_seq seq(array, array + 3); v.assign(seq.begin(), seq.end()); diff --git a/libstdc++-v3/testsuite/23_containers/vector/types/pmr_typedefs_debug.cc b/libstdc++-v3/testsuite/23_containers/vector/types/pmr_typedefs_debug.cc new file mode 100644 index 00000000000..f0da4ca511f --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/types/pmr_typedefs_debug.cc @@ -0,0 +1,25 @@ +// Copyright (C) 2018 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 -D_GLIBCXX_DEBUG" } +// { dg-do compile { target c++17 } } + +#include <debug/vector> +static_assert(std::is_same_v< + std::pmr::vector<int>, + __gnu_debug::vector<int, std::pmr::polymorphic_allocator<int>> + >); |