aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite
diff options
context:
space:
mode:
authorYvan Roux <yvan.roux@linaro.org>2017-02-06 13:25:57 +0100
committerYvan Roux <yvan.roux@linaro.org>2017-02-06 13:25:57 +0100
commitaad858c02179d21167c43b18b31b3e8008dae1ed (patch)
tree78f5e2544647f1c1c644c0b5e999d8b97467acfb /libstdc++-v3/testsuite
parentb300ea83b9875ebfafb5f2d652d6eb7c3a57c497 (diff)
Merge branches/gcc-6-branch rev 245201.
Change-Id: Ibc46d8742ef080683f302f5623b4907e9622ac4c
Diffstat (limited to 'libstdc++-v3/testsuite')
-rw-r--r--libstdc++-v3/testsuite/20_util/tuple/cons/allocator_with_any.cc42
-rw-r--r--libstdc++-v3/testsuite/21_strings/basic_string/allocator/char/copy_assign.cc37
-rw-r--r--libstdc++-v3/testsuite/21_strings/basic_string/allocator/wchar_t/copy_assign.cc37
-rw-r--r--libstdc++-v3/testsuite/23_containers/list/operations/78389.cc74
-rw-r--r--libstdc++-v3/testsuite/25_algorithms/search/78346.cc118
-rw-r--r--libstdc++-v3/testsuite/experimental/array/make_array.cc18
-rw-r--r--libstdc++-v3/testsuite/util/testsuite_allocator.h2
7 files changed, 321 insertions, 7 deletions
diff --git a/libstdc++-v3/testsuite/20_util/tuple/cons/allocator_with_any.cc b/libstdc++-v3/testsuite/20_util/tuple/cons/allocator_with_any.cc
new file mode 100644
index 00000000000..9f86c93e378
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/tuple/cons/allocator_with_any.cc
@@ -0,0 +1,42 @@
+// { dg-do run { target c++14 } }
+
+// Copyright (C) 2016 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/>.
+
+
+// NOTE: This makes use of the fact that we know how moveable
+// is implemented on tuple. If the implementation changed
+// this test may begin to fail.
+
+#include <tuple>
+#include <experimental/any>
+#include <testsuite_hooks.h>
+
+using std::experimental::any;
+
+void test01()
+{
+ std::tuple<any, any> t(std::allocator_arg,
+ std::allocator<any>{});
+ VERIFY(std::get<0>(t).empty());
+ VERIFY(std::get<1>(t).empty());
+}
+
+int main()
+{
+ test01();
+}
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/allocator/char/copy_assign.cc b/libstdc++-v3/testsuite/21_strings/basic_string/allocator/char/copy_assign.cc
index 3c8e440120e..645e3cb7bfe 100644
--- a/libstdc++-v3/testsuite/21_strings/basic_string/allocator/char/copy_assign.cc
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/allocator/char/copy_assign.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2015-2016 Free Software Foundation, Inc.
+// 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
@@ -20,6 +20,7 @@
#include <string>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
+#include <ext/throw_allocator.h>
#if _GLIBCXX_USE_CXX11_ABI
using C = char;
@@ -100,10 +101,44 @@ void test02()
VERIFY(1 == v5.get_allocator().get_personality());
}
+void test03()
+{
+ // PR libstdc++/79254
+ using throw_alloc = __gnu_cxx::throw_allocator_limit<C>;
+ typedef propagating_allocator<C, true, throw_alloc> alloc_type;
+ typedef std::basic_string<C, traits, alloc_type> test_type;
+ alloc_type a1(1), a2(2);
+ throw_alloc::set_limit(2); // Throw on third allocation (during assignment).
+ const C* s1 = "a string that is longer than a small string";
+ const C* s2 = "another string that is longer than a small string";
+ test_type v1(s1, a1);
+ test_type v2(s2, a2);
+ bool caught = false;
+ try {
+ v1 = v2;
+ } catch (__gnu_cxx::forced_error&) {
+ caught = true;
+ }
+ VERIFY( caught );
+ VERIFY( v1 == s1 );
+ VERIFY( v1.get_allocator() == a1 );
+
+ throw_alloc::set_limit(1); // Allow one more allocation (and no more).
+ test_type v3(s1, a1);
+ // No allocation when allocators are equal and capacity is sufficient:
+ VERIFY( v1.capacity() >= v3.size() );
+ v1 = v3;
+ // No allocation when the contents fit in the small-string buffer:
+ v2 = "sso";
+ v1 = v2;
+ VERIFY( v1.get_allocator() == a2 );
+}
+
int main()
{
test01();
test02();
+ test03();
return 0;
}
#else
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/allocator/wchar_t/copy_assign.cc b/libstdc++-v3/testsuite/21_strings/basic_string/allocator/wchar_t/copy_assign.cc
index 3ac15bbf821..01cdba4eead 100644
--- a/libstdc++-v3/testsuite/21_strings/basic_string/allocator/wchar_t/copy_assign.cc
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/allocator/wchar_t/copy_assign.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2015-2016 Free Software Foundation, Inc.
+// 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
@@ -20,6 +20,7 @@
#include <string>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
+#include <ext/throw_allocator.h>
#if _GLIBCXX_USE_CXX11_ABI
using C = wchar_t;
@@ -100,10 +101,44 @@ void test02()
VERIFY(1 == v5.get_allocator().get_personality());
}
+void test03()
+{
+ // PR libstdc++/79254
+ using throw_alloc = __gnu_cxx::throw_allocator_limit<C>;
+ typedef propagating_allocator<C, true, throw_alloc> alloc_type;
+ typedef std::basic_string<C, traits, alloc_type> test_type;
+ alloc_type a1(1), a2(2);
+ throw_alloc::set_limit(2); // Throw on third allocation (during assignment).
+ const C* s1 = L"a string that is longer than a small string";
+ const C* s2 = L"another string that is longer than a small string";
+ test_type v1(s1, a1);
+ test_type v2(s2, a2);
+ bool caught = false;
+ try {
+ v1 = v2;
+ } catch (__gnu_cxx::forced_error&) {
+ caught = true;
+ }
+ VERIFY( caught );
+ VERIFY( v1 == s1 );
+ VERIFY( v1.get_allocator() == a1 );
+
+ throw_alloc::set_limit(1); // Allow one more allocation (and no more).
+ test_type v3(s1, a1);
+ // No allocation when allocators are equal and capacity is sufficient:
+ VERIFY( v1.capacity() >= v3.size() );
+ v1 = v3;
+ // No allocation when the contents fit in the small-string buffer:
+ v2 = L"sso";
+ v1 = v2;
+ VERIFY( v1.get_allocator() == a2 );
+}
+
int main()
{
test01();
test02();
+ test03();
return 0;
}
#else
diff --git a/libstdc++-v3/testsuite/23_containers/list/operations/78389.cc b/libstdc++-v3/testsuite/23_containers/list/operations/78389.cc
new file mode 100644
index 00000000000..ac36f9c94d8
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/list/operations/78389.cc
@@ -0,0 +1,74 @@
+// { dg-do run { target c++11 } }
+
+// 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.2.2.4 list operations [lib.list.ops]
+
+#include <testsuite_hooks.h>
+
+#include <list>
+
+struct ThrowingComparator
+{
+ unsigned int throw_after = 0;
+ unsigned int count = 0;
+ bool operator()(int, int) {
+ if (++count >= throw_after) {
+ throw 666;
+ }
+ return true;
+ }
+};
+
+struct X
+{
+ X() = default;
+ X(int) {}
+};
+
+unsigned int throw_after_X = 0;
+unsigned int count_X = 0;
+
+bool operator<(const X&, const X&) {
+ if (++count_X >= throw_after_X) {
+ throw 666;
+ }
+ return true;
+}
+
+
+int main()
+{
+ std::list<int> a{1, 2, 3, 4};
+ std::list<int> b{5, 6, 7, 8, 9, 10, 11, 12};
+ try {
+ a.merge(b, ThrowingComparator{4});
+ } catch (...) {
+ }
+ VERIFY(a.size() == std::distance(a.begin(), a.end()) &&
+ b.size() == std::distance(b.begin(), b.end()));
+ std::list<X> ax{1, 2, 3, 4};
+ std::list<X> bx{5, 6, 7, 8, 9, 10, 11, 12};
+ throw_after_X = 4;
+ try {
+ ax.merge(bx);
+ } catch (...) {
+ }
+ VERIFY(ax.size() == std::distance(ax.begin(), ax.end()) &&
+ bx.size() == std::distance(bx.begin(), bx.end()));
+}
diff --git a/libstdc++-v3/testsuite/25_algorithms/search/78346.cc b/libstdc++-v3/testsuite/25_algorithms/search/78346.cc
new file mode 100644
index 00000000000..6f003bdb9e6
--- /dev/null
+++ b/libstdc++-v3/testsuite/25_algorithms/search/78346.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-do run { target c++11 } }
+
+#include <algorithm>
+#include <testsuite_hooks.h>
+
+bool values[100];
+
+unsigned next_id()
+{
+ static unsigned counter = 0;
+ VERIFY(counter < 100);
+ return counter++;
+}
+
+struct value
+{
+ int val;
+ const unsigned id;
+
+ value(int i = 0) : val(i), id(next_id()) { values[id] = true; }
+ value(const value& v) : val(v.val), id(next_id()) { values[id] = true; }
+ value& operator=(const value& v) { val = v.val; return *this; }
+ ~value() { values[id] = false; }
+};
+
+bool operator<(const value& lhs, const value& rhs)
+{
+ if (!values[lhs.id])
+ throw lhs.id;
+ if (!values[rhs.id])
+ throw rhs.id;
+ return lhs.val < rhs.val;
+}
+
+bool operator==(const value& lhs, const value& rhs)
+{
+ if (!values[lhs.id])
+ throw lhs.id;
+ if (!values[rhs.id])
+ throw rhs.id;
+ return lhs.val == rhs.val;
+}
+
+// A forward iterator that fails to meet the requirement that for any
+// two dereferenceable forward iterators, a == b implies &*a == &*b
+struct stashing_iterator
+{
+ typedef std::forward_iterator_tag iterator_category;
+ typedef value value_type;
+ typedef value_type const* pointer;
+ typedef value_type const& reference;
+ typedef std::ptrdiff_t difference_type;
+
+ stashing_iterator() : ptr(), stashed() { }
+ stashing_iterator(pointer p) : ptr(p), stashed() { stash(); }
+ stashing_iterator(const stashing_iterator&) = default;
+ stashing_iterator& operator=(const stashing_iterator&) = default;
+
+ stashing_iterator& operator++()
+ {
+ ++ptr;
+ stash();
+ return *this;
+ }
+
+ stashing_iterator operator++(int)
+ {
+ stashing_iterator i = *this;
+ ++*this;
+ return i;
+ }
+
+ reference operator*() const { return stashed; }
+ pointer operator->() const { return &**this; }
+
+ bool operator==(const stashing_iterator& i) const { return ptr == i.ptr; }
+ bool operator!=(const stashing_iterator& i) const { return !(*this == i); }
+
+private:
+ void stash()
+ {
+ if (ptr)
+ stashed = *ptr;
+ }
+
+ pointer ptr;
+ value_type stashed;
+};
+
+void
+test01()
+{
+ value s[] = { 0, 1, 2, 3, 4, 5 };
+ std::search(s, s+6, stashing_iterator(s), stashing_iterator(s+4));
+}
+
+int
+main()
+{
+ test01();
+}
diff --git a/libstdc++-v3/testsuite/experimental/array/make_array.cc b/libstdc++-v3/testsuite/experimental/array/make_array.cc
index 0ae188b0f8b..75f5333639c 100644
--- a/libstdc++-v3/testsuite/experimental/array/make_array.cc
+++ b/libstdc++-v3/testsuite/experimental/array/make_array.cc
@@ -1,7 +1,6 @@
-// { dg-options "-std=gnu++14" }
-// { dg-do compile }
+// { dg-do compile { target c++14 } }
-// Copyright (C) 2015-2016 Free Software Foundation, Inc.
+// 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
@@ -19,6 +18,7 @@
// <http://www.gnu.org/licenses/>.
#include <experimental/array>
+#include <functional> // for std::ref and std::reference_wrapper
struct MoveOnly
{
@@ -27,7 +27,7 @@ struct MoveOnly
MoveOnly& operator=(MoveOnly&&) = default;
};
-int main()
+void test01()
{
char x[42];
std::array<char, 42> y = std::experimental::to_array(x);
@@ -45,3 +45,13 @@ int main()
= std::experimental::make_array(1,2L, 3);
constexpr std::array<MoveOnly, 1> zzz2 = std::experimental::make_array(MoveOnly{});
}
+
+void test02()
+{
+ // PR libstdc++/79195
+ struct A {};
+ struct B : A {};
+ struct C : A {};
+ auto arr = std::experimental::make_array<A>(B{}, C{});
+ static_assert(std::is_same<decltype(arr), std::array<A, 2>>::value, "");
+}
diff --git a/libstdc++-v3/testsuite/util/testsuite_allocator.h b/libstdc++-v3/testsuite/util/testsuite_allocator.h
index 4884600bcb8..f597a3846ab 100644
--- a/libstdc++-v3/testsuite/util/testsuite_allocator.h
+++ b/libstdc++-v3/testsuite/util/testsuite_allocator.h
@@ -287,7 +287,7 @@ namespace __gnu_test
Alloc& base() { return *this; }
const Alloc& base() const { return *this; }
- void swap_base(Alloc& b) { swap(b, this->base()); }
+ void swap_base(Alloc& b) { using std::swap; swap(b, this->base()); }
public:
typedef typename check_consistent_alloc_value_type<Tp, Alloc>::value_type