aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite
diff options
context:
space:
mode:
authorYvan Roux <yvan.roux@linaro.org>2016-11-14 11:08:49 +0100
committerYvan Roux <yvan.roux@linaro.org>2016-11-15 08:50:52 +0000
commit28192592ae19dc5ba0996503fbb87c2d7f7be769 (patch)
tree5a574b72d96a2748b3012b407581295592c58788 /libstdc++-v3/testsuite
parent157a219d57b8ea803b58c0e70a05dff3cfd18d31 (diff)
Merge branches/gcc-6-branch rev 242371.
Change-Id: Ia4fb8e9e94629da786722b5e68605dc8bb971741
Diffstat (limited to 'libstdc++-v3/testsuite')
-rw-r--r--libstdc++-v3/testsuite/20_util/allocator/void.cc40
-rw-r--r--libstdc++-v3/testsuite/20_util/function/77322.cc26
-rw-r--r--libstdc++-v3/testsuite/20_util/function/cons/72820.cc28
-rw-r--r--libstdc++-v3/testsuite/20_util/reference_wrapper/invoke-2.cc2
-rw-r--r--libstdc++-v3/testsuite/20_util/unique_ptr/assign/48635_neg.cc4
-rw-r--r--libstdc++-v3/testsuite/20_util/unique_ptr/assign/assign_neg.cc21
-rw-r--r--libstdc++-v3/testsuite/20_util/unique_ptr/assign/cv_qual.cc23
-rw-r--r--libstdc++-v3/testsuite/20_util/unique_ptr/cons/77990.cc28
-rw-r--r--libstdc++-v3/testsuite/20_util/unique_ptr/cons/cv_qual.cc26
-rw-r--r--libstdc++-v3/testsuite/20_util/unique_ptr/cons/cv_qual_neg.cc73
-rw-r--r--libstdc++-v3/testsuite/20_util/unique_ptr/modifiers/cv_qual.cc11
-rw-r--r--libstdc++-v3/testsuite/20_util/unique_ptr/modifiers/reset_neg.cc28
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/default_random_engine.cc4
-rw-r--r--libstdc++-v3/testsuite/experimental/algorithm/sample.cc1
-rw-r--r--libstdc++-v3/testsuite/experimental/optional/77288.cc406
-rw-r--r--libstdc++-v3/testsuite/experimental/optional/assignment/5.cc11
-rw-r--r--libstdc++-v3/testsuite/experimental/optional/cons/77727.cc51
-rw-r--r--libstdc++-v3/testsuite/experimental/optional/cons/value.cc27
18 files changed, 741 insertions, 69 deletions
diff --git a/libstdc++-v3/testsuite/20_util/allocator/void.cc b/libstdc++-v3/testsuite/20_util/allocator/void.cc
new file mode 100644
index 00000000000..34f3beb1345
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/allocator/void.cc
@@ -0,0 +1,40 @@
+// 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/>.
+
+// { dg-options "-std=gnu++11" }
+
+#include <memory>
+#include <testsuite_hooks.h>
+
+template class std::allocator<void>;
+
+void
+test01()
+{
+ int i;
+ using alloc_type = std::allocator<void>;
+ alloc_type a;
+ std::allocator_traits<alloc_type>::construct(a, &i, 42);
+ VERIFY( i == 42 );
+ std::allocator_traits<alloc_type>::destroy(a, &i);
+}
+
+int
+main()
+{
+ test01();
+}
diff --git a/libstdc++-v3/testsuite/20_util/function/77322.cc b/libstdc++-v3/testsuite/20_util/function/77322.cc
new file mode 100644
index 00000000000..52abdf6b205
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/function/77322.cc
@@ -0,0 +1,26 @@
+// 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/>.
+
+// { dg-options "-std=gnu++11" }
+// { dg-do compile }
+
+#include <functional>
+
+// PR libstdc++/77322
+std::function<void()> f, g;
+static_assert( noexcept(f.swap(g)), "member swap is noexcept" );
+static_assert( noexcept(swap(f, g)), "non-member swap is noexcept" );
diff --git a/libstdc++-v3/testsuite/20_util/function/cons/72820.cc b/libstdc++-v3/testsuite/20_util/function/cons/72820.cc
new file mode 100644
index 00000000000..1e4e0e8aabf
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/function/cons/72820.cc
@@ -0,0 +1,28 @@
+// 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/>.
+
+// { dg-options "-std=gnu++11" }
+// { dg-do compile }
+
+#include <functional>
+
+struct foo {
+ void operator()() { }
+ static void* operator new(std::size_t, void* p);
+};
+
+std::function<void()> f = foo{};
diff --git a/libstdc++-v3/testsuite/20_util/reference_wrapper/invoke-2.cc b/libstdc++-v3/testsuite/20_util/reference_wrapper/invoke-2.cc
index 89b81ac94a0..3492c744a04 100644
--- a/libstdc++-v3/testsuite/20_util/reference_wrapper/invoke-2.cc
+++ b/libstdc++-v3/testsuite/20_util/reference_wrapper/invoke-2.cc
@@ -1,5 +1,5 @@
// { dg-options "-std=gnu++11" }
-// { dg-do compile}
+// { dg-do compile }
// Copyright (C) 2011-2016 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/assign/48635_neg.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/assign/48635_neg.cc
index 16ff8aee650..785f9ad4cfd 100644
--- a/libstdc++-v3/testsuite/20_util/unique_ptr/assign/48635_neg.cc
+++ b/libstdc++-v3/testsuite/20_util/unique_ptr/assign/48635_neg.cc
@@ -43,10 +43,10 @@ void f()
std::unique_ptr<int, D&> ud(nullptr, d);
ub = std::move(ud); // { dg-error "no match" }
ub2 = ud; // { dg-error "no match" }
-// { dg-error "no type" "" { target *-*-* } 269 }
+// { dg-error "no type" "" { target *-*-* } 272 }
std::unique_ptr<int[], B&> uba(nullptr, b);
std::unique_ptr<int[], D&> uda(nullptr, d);
uba = std::move(uda); // { dg-error "no match" }
-// { dg-error "no type" "" { target *-*-* } 537 }
+// { dg-error "no type" "" { target *-*-* } 540 }
}
diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/assign/assign_neg.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/assign/assign_neg.cc
index 6482016e02b..a44eff5fbcb 100644
--- a/libstdc++-v3/testsuite/20_util/unique_ptr/assign/assign_neg.cc
+++ b/libstdc++-v3/testsuite/20_util/unique_ptr/assign/assign_neg.cc
@@ -49,4 +49,25 @@ test03()
std::unique_ptr<int[2]> p2 = p1; // { dg-error "deleted" }
}
+struct base_pointer { operator base*() const { return nullptr; } };
+
+template<typename T>
+struct deleter
+{
+ deleter() = default;
+ template<typename U>
+ deleter(const deleter<U>) { }
+ typedef T pointer;
+ void operator()(T) const { }
+};
+
+void
+test04()
+{
+ // Disallow conversions from incompatible deleter
+ std::unique_ptr<derived[], deleter<base_pointer>> p;
+ std::unique_ptr<base[], deleter<base*>> upA;
+ upA = std::move(p); // { dg-error "no match" }
+}
+
// { dg-prune-output "include" }
diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/assign/cv_qual.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/assign/cv_qual.cc
index 640a3b7d907..605149c5b78 100644
--- a/libstdc++-v3/testsuite/20_util/unique_ptr/assign/cv_qual.cc
+++ b/libstdc++-v3/testsuite/20_util/unique_ptr/assign/cv_qual.cc
@@ -66,26 +66,3 @@ test03()
std::unique_ptr<const volatile A[]> cvA;
cvA = std::move(upA);
}
-
-struct A_pointer { operator A*() const { return nullptr; } };
-
-template<typename T>
-struct deleter
-{
- deleter() = default;
- template<typename U>
- deleter(const deleter<U>) { }
- typedef T pointer;
- void operator()(T) const { }
-};
-
-void
-test04()
-{
- // Disallow conversions from incompatible deleter
- std::unique_ptr<B[], deleter<A_pointer>> p;
- std::unique_ptr<A[], deleter<A*>> upA;
- upA = std::move(p); // { dg-error "no match" }
- // { dg-error "no type" "" { target *-*-* } 537 }
- // { dg-error "no matching function" "" { target *-*-* } 614 }
-}
diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/cons/77990.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/cons/77990.cc
new file mode 100644
index 00000000000..1acc3135d3b
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/unique_ptr/cons/77990.cc
@@ -0,0 +1,28 @@
+// 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/>.
+
+// { dg-options "-std=gnu++11" }
+// { dg-do compile }
+
+#include <memory>
+
+struct D {
+ D() = default;
+ D(const D&) = delete;
+ void operator()(int*);
+};
+std::unique_ptr<int, D> p((int*)nullptr); // PR libstdc++/77990
diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/cons/cv_qual.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/cons/cv_qual.cc
index 078ecbb49eb..6e190713707 100644
--- a/libstdc++-v3/testsuite/20_util/unique_ptr/cons/cv_qual.cc
+++ b/libstdc++-v3/testsuite/20_util/unique_ptr/cons/cv_qual.cc
@@ -100,30 +100,4 @@ test07()
std::unique_ptr<const A[]> cA2((A*)p);
std::unique_ptr<volatile A[]> vA2((A*)p);
std::unique_ptr<const volatile A[]> cvA2((A*)p);
- // Disallow conversions from user-defined pointer-like types
- // for the array version
- std::unique_ptr<A[]> upA3(p); // { dg-error "no matching function" }
- std::unique_ptr<const A[]> cA3(p); // { dg-error "no matching function" }
- std::unique_ptr<volatile A[]> vA3(p); // { dg-error "no matching function" }
- std::unique_ptr<const volatile A[]> cvA3(p); // { dg-error "no matching function" }
- // { dg-error "no type" "" { target *-*-* } 445 }
}
-
-template<typename T>
-struct deleter
-{
- deleter() = default;
- template<typename U>
- deleter(const deleter<U>) { }
- typedef T pointer;
- void operator()(T) const { }
-};
-
-void
-test08()
-{
- // Disallow conversions from non-assignable deleter
- std::unique_ptr<B[], deleter<A_pointer>> p;
- std::unique_ptr<A[], deleter<A*>> upA(std::move(p)); // { dg-error "no matching function" }
-}
-
diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/cons/cv_qual_neg.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/cons/cv_qual_neg.cc
new file mode 100644
index 00000000000..285a0b994c9
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/unique_ptr/cons/cv_qual_neg.cc
@@ -0,0 +1,73 @@
+// { dg-options "-std=gnu++11" }
+// { dg-do compile }
+
+// 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/>.
+
+// 20.7.1 Class template unique_ptr [unique.ptr]
+
+#include <memory>
+
+struct A { virtual ~A() = default; };
+
+struct B : A { };
+
+// Construction from objects with different cv-qualification
+
+struct A_pointer { operator A*() const { return nullptr; } };
+
+void
+test07()
+{
+ A_pointer p;
+ // Disallow conversions from user-defined pointer-like types
+ // for the array version
+ std::unique_ptr<A[]> upA3(p); // { dg-error "no matching function" }
+ std::unique_ptr<const A[]> cA3(p); // { dg-error "no matching function" }
+ std::unique_ptr<volatile A[]> vA3(p); // { dg-error "no matching function" }
+ std::unique_ptr<const volatile A[]> cvA3(p); // { dg-error "no matching function" }
+ // { dg-error "no type" "" { target *-*-* } 448 }
+}
+
+template<typename T>
+struct deleter
+{
+ deleter() = default;
+ template<typename U>
+ deleter(const deleter<U>) { }
+ typedef T pointer;
+ void operator()(T) const { }
+};
+
+void
+test08()
+{
+ // Disallow conversions from non-assignable deleter
+ std::unique_ptr<A[], deleter<A_pointer>> p;
+ std::unique_ptr<A[], deleter<A*>> upA(std::move(p)); // { dg-error "no matching function" }
+}
+
+void
+test011()
+{
+ // Disallow conversions between different array types.
+ std::unique_ptr<B[]> upB;
+
+ std::unique_ptr<const A[]> cA(std::move(upB)); // { dg-error "no matching function" }
+ std::unique_ptr<volatile A[]> vA(std::move(upB)); // { dg-error "no matching function" }
+ std::unique_ptr<const volatile A[]> cvA(std::move(upB)); // { dg-error "no matching function" }
+}
diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/modifiers/cv_qual.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/modifiers/cv_qual.cc
index 6bf0ce42bce..9c63fd67793 100644
--- a/libstdc++-v3/testsuite/20_util/unique_ptr/modifiers/cv_qual.cc
+++ b/libstdc++-v3/testsuite/20_util/unique_ptr/modifiers/cv_qual.cc
@@ -87,15 +87,4 @@ test07()
vA2.reset((A*)p);
std::unique_ptr<const volatile A[]> cvA2;
cvA2.reset((A*)p);
- // Disallow conversions from user-defined pointer-like types
- // for the array version
- std::unique_ptr<A[]> upA3;
- upA3.reset(p); // { dg-error "no matching function" }
- std::unique_ptr<const A[]> cA3;
- cA3.reset(p); // { dg-error "no matching function" }
- std::unique_ptr<volatile A[]> vA3;
- vA3.reset(p); // { dg-error "no matching function" }
- std::unique_ptr<const volatile A[]> cvA3;
- cvA3.reset(p); // { dg-error "no matching function" }
- // { dg-error "no matching function" "" { target *-*-* } 614 }
}
diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/modifiers/reset_neg.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/modifiers/reset_neg.cc
index 1a3f981eb7c..1fd7e3199b4 100644
--- a/libstdc++-v3/testsuite/20_util/unique_ptr/modifiers/reset_neg.cc
+++ b/libstdc++-v3/testsuite/20_util/unique_ptr/modifiers/reset_neg.cc
@@ -22,17 +22,37 @@
struct A
{
+ virtual ~A() { }
};
struct B : A
{
- virtual ~B() { }
};
-void test01()
+void
+test01()
{
std::unique_ptr<B[]> up;
- up.reset(new A[3]); // { dg-error "" }
+ up.reset(new A[3]); // { dg-error "no matching function" }
+
+ std::unique_ptr<A[]> up2;
+ up2.reset(new B[3]); // { dg-error "no matching function" }
}
-// { dg-prune-output "include" }
+struct A_pointer { operator A*() const { return nullptr; } };
+
+void
+test02()
+{
+ A_pointer p;
+ // Disallow conversions from user-defined pointer-like types
+ // for the array version
+ std::unique_ptr<A[]> upA3;
+ upA3.reset(p); // { dg-error "no matching function" }
+ std::unique_ptr<const A[]> cA3;
+ cA3.reset(p); // { dg-error "no matching function" }
+ std::unique_ptr<volatile A[]> vA3;
+ vA3.reset(p); // { dg-error "no matching function" }
+ std::unique_ptr<const volatile A[]> cvA3;
+ cvA3.reset(p); // { dg-error "no matching function" }
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/random/default_random_engine.cc b/libstdc++-v3/testsuite/26_numerics/random/default_random_engine.cc
index d7ca5fc248b..3893bc7c715 100644
--- a/libstdc++-v3/testsuite/26_numerics/random/default_random_engine.cc
+++ b/libstdc++-v3/testsuite/26_numerics/random/default_random_engine.cc
@@ -20,7 +20,7 @@
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
-// 26.4.5 Engines and egine adaptors with predefined parameters [rand.predef]
+// 26.4.5 Engines and engine adaptors with predefined parameters [rand.predef]
// 26.4.5 [10]
#include <random>
@@ -38,7 +38,7 @@ test01()
std::minstd_rand0 b;
b.discard(9999);
- assert( a() == b() );
+ VERIFY( a() == b() );
}
int main()
diff --git a/libstdc++-v3/testsuite/experimental/algorithm/sample.cc b/libstdc++-v3/testsuite/experimental/algorithm/sample.cc
index 0349d29d9ff..98ebace7879 100644
--- a/libstdc++-v3/testsuite/experimental/algorithm/sample.cc
+++ b/libstdc++-v3/testsuite/experimental/algorithm/sample.cc
@@ -22,6 +22,7 @@
#include <sstream>
#include <forward_list>
#include <vector>
+#include <random>
#include <testsuite_hooks.h>
std::mt19937 rng;
diff --git a/libstdc++-v3/testsuite/experimental/optional/77288.cc b/libstdc++-v3/testsuite/experimental/optional/77288.cc
new file mode 100644
index 00000000000..5b6a6c8aa6a
--- /dev/null
+++ b/libstdc++-v3/testsuite/experimental/optional/77288.cc
@@ -0,0 +1,406 @@
+// { dg-options "-std=gnu++14" }
+// { dg-do run }
+
+// 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 moved_to of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <experimental/optional>
+#include <experimental/any>
+
+using std::experimental::optional;
+
+#include <testsuite_hooks.h>
+
+void test01()
+{
+ optional<optional<int>> nested_element;
+ optional<int> element = {};
+ nested_element = element;
+ VERIFY(nested_element);
+}
+
+template <class T>
+struct service_result
+{
+ static optional<T> get_result()
+ {
+ T sr;
+ return sr;
+ }
+
+ static optional<T> get_result_with_cond(bool cond)
+ {
+ if (cond)
+ return T{};
+ return {};
+ }
+};
+
+void test02()
+{
+ VERIFY(service_result<int>::get_result());
+ VERIFY(service_result<optional<int>>::get_result());
+ VERIFY(service_result<int>::get_result_with_cond(true));
+ VERIFY(service_result<optional<int>>::get_result_with_cond(true));
+ VERIFY(!service_result<int>::get_result_with_cond(false));
+ VERIFY(!service_result<optional<int>>::get_result_with_cond(false));
+}
+
+struct Widget
+{
+ Widget(int) {}
+ Widget(optional<int>) {}
+};
+
+
+void test03()
+{
+ optional<Widget> w;
+ w = optional<int>();
+ VERIFY(w);
+ static_assert(!std::is_assignable<optional<Widget>&,
+ optional<short>>::value);
+ w = optional<optional<int>>();
+ VERIFY(!w);
+ static_assert(!std::is_assignable<optional<Widget>&,
+ optional<optional<short>>>::value);
+
+ optional<Widget> w2{optional<int>()};
+ VERIFY(w2);
+ optional<Widget> w3 = optional<int>();
+ VERIFY(w3);
+ optional<Widget> w4{optional<short>()};
+ VERIFY(w4);
+ static_assert(!std::is_convertible<optional<short>&&,
+ optional<Widget>>::value);
+
+ optional<Widget> w6{optional<optional<int>>()};
+ VERIFY(!w6);
+ optional<Widget> w7 = optional<optional<int>>();
+ VERIFY(!w7);
+ optional<Widget> w8{optional<optional<short>>()};
+ VERIFY(!w8);
+ static_assert(!std::is_convertible<optional<optional<short>>&&,
+ optional<Widget>>::value);
+ optional<Widget> w10{optional<optional<short>>(10)};
+ VERIFY(w10);
+ optional<Widget> w11 = std::experimental::nullopt;
+ VERIFY(!w11);
+ optional<Widget> w12 = {};
+ VERIFY(!w12);
+ optional<Widget> w13{std::experimental::nullopt};
+ VERIFY(!w13);
+ optional<Widget> w14;
+ w14 = {};
+ VERIFY(!w14);
+}
+
+struct Widget2
+{
+ Widget2(int) {}
+ Widget2(optional<int>) {}
+ Widget2& operator=(int) {return *this;}
+ Widget2& operator=(optional<int>) {return *this;}
+};
+
+void test04()
+{
+ optional<Widget2> w;
+ w = optional<int>();
+ VERIFY(w);
+ w = optional<short>();
+ VERIFY(w);
+ w = optional<optional<int>>();
+ VERIFY(!w);
+ w = optional<optional<short>>();
+ VERIFY(!w);
+ w = optional<optional<short>>(10);
+ optional<Widget2> w2 = std::experimental::nullopt;
+ VERIFY(!w2);
+ optional<Widget2> w3 = {};
+ VERIFY(!w3);
+ optional<Widget2> w4{std::experimental::nullopt};
+ VERIFY(!w4);
+ optional<Widget2> w5;
+ w5 = {};
+ VERIFY(!w5);
+}
+
+struct Thingy
+{
+ Thingy(int) {}
+ Thingy(Widget) {}
+};
+
+void test05()
+{
+ optional<Thingy> ot;
+
+ static_assert(!std::is_assignable<optional<Thingy>&,
+ optional<int>>::value);
+ static_assert(std::is_assignable<optional<Thingy>&,
+ optional<short>>::value);
+ static_assert(!std::is_assignable<optional<Thingy>&,
+ optional<optional<int>>>::value);
+ ot = optional<Widget>();
+ VERIFY(!ot);
+ optional<Thingy> ot2{optional<int>()};
+ VERIFY(ot2);
+ static_assert(!std::is_convertible<optional<int>&&,
+ optional<Thingy>>::value);
+ optional<Thingy> ot3{optional<short>()};
+ VERIFY(!ot3);
+ optional<Thingy> ot4 = optional<short>();
+ VERIFY(!ot4);
+
+ optional<Thingy> ot5{optional<optional<int>>()};
+ VERIFY(!ot5);
+ static_assert(!std::is_convertible<optional<optional<int>>&&,
+ optional<Thingy>>::value);
+
+ optional<Thingy> ot7{optional<Widget>()};
+ VERIFY(!ot7);
+ optional<Thingy> ot8 = optional<Widget>();
+ VERIFY(!ot8);
+ static_assert(!std::is_constructible<optional<Thingy>,
+ optional<optional<short>>>::value);
+ static_assert(!std::is_convertible<optional<optional<short>>,
+ optional<Thingy>>::value);
+ static_assert(!std::is_assignable<optional<Thingy>&,
+ optional<optional<short>>>::value);
+ optional<Thingy> ot9 = std::experimental::nullopt;
+ VERIFY(!ot9);
+ optional<Thingy> ot10 = {};
+ VERIFY(!ot10);
+ optional<Thingy> ot11{std::experimental::nullopt};
+ VERIFY(!ot11);
+ optional<Thingy> ot12;
+ ot12 = {};
+ VERIFY(!ot12);
+}
+
+struct RvalueConstructible
+{
+ RvalueConstructible(int) {}
+ RvalueConstructible(optional<int>&&) {}
+};
+
+void test06()
+{
+ optional<int> oi;
+ optional<RvalueConstructible> ori;
+ static_assert(!std::is_assignable<optional<RvalueConstructible>&,
+ optional<int>&>::value);
+ ori = std::move(oi);
+ VERIFY(ori);
+
+ optional<optional<int>> ooi;
+ static_assert(!std::is_assignable<optional<RvalueConstructible>&,
+ optional<optional<int>>&>::value);
+ ori = std::move(ooi);
+ VERIFY(!ori);
+
+ static_assert(!std::is_constructible<optional<RvalueConstructible>,
+ optional<int>&>::value);
+ static_assert(!std::is_convertible<optional<int>&,
+ optional<RvalueConstructible>>::value);
+
+ optional<RvalueConstructible> ori2(std::move(oi));
+ VERIFY(ori2);
+ optional<RvalueConstructible> ori3 = std::move(oi);
+ VERIFY(ori3);
+
+ static_assert(!std::is_constructible<optional<RvalueConstructible>,
+ optional<optional<int>>&>::value);
+ static_assert(!std::is_convertible<optional<optional<int>>&,
+ optional<RvalueConstructible>>::value);
+ optional<RvalueConstructible> ori6(std::move(ooi));
+ VERIFY(!ori6);
+ optional<RvalueConstructible> ori7 = std::move(ooi);
+ VERIFY(!ori7);
+ optional<RvalueConstructible> ori8 = std::experimental::nullopt;
+ VERIFY(!ori8);
+ optional<RvalueConstructible> ori9 = {};
+ VERIFY(!ori9);
+ optional<RvalueConstructible> ori10{std::experimental::nullopt};
+ VERIFY(!ori10);
+ optional<RvalueConstructible> ori11;
+ ori11 = {};
+ VERIFY(!ori11);
+}
+
+struct Thingy2
+{
+ Thingy2(int) {}
+ explicit Thingy2(optional<int>) {}
+ Thingy2(Widget) {}
+};
+
+void test07()
+{
+ optional<Thingy2> ot{optional<int>{}};
+ VERIFY(ot);
+ static_assert(!std::is_convertible<optional<int>,
+ optional<Thingy2>>::value);
+ optional<Thingy2> ot2{optional<short>{}};
+ VERIFY(ot2);
+ static_assert(!std::is_convertible<optional<short>,
+ optional<Thingy2>>::value);
+ optional<Thingy2> ot3{optional<optional<int>>{}};
+ VERIFY(!ot3);
+ static_assert(!std::is_convertible<optional<optional<int>>,
+ optional<Thingy2>>::value);
+ optional<Thingy2> ot4{optional<optional<short>>{}};
+ VERIFY(!ot4);
+ static_assert(!std::is_convertible<optional<optional<short>>,
+ optional<Thingy2>>::value);
+
+ optional<Thingy2> ot5{optional<Widget>{}};
+ VERIFY(!ot5);
+ optional<Thingy2> ot6 = optional<Widget>();
+ VERIFY(!ot6);
+
+ static_assert(!std::is_assignable<optional<Thingy2>&,
+ optional<int>>::value);
+ static_assert(!std::is_assignable<optional<Thingy2>&,
+ optional<short>>::value);
+ static_assert(!std::is_assignable<optional<Thingy2>&,
+ optional<optional<int>>>::value);
+ static_assert(!std::is_assignable<optional<Thingy2>&,
+ optional<optional<short>>>::value);
+ optional<Thingy2> ot7;
+ ot = optional<Widget>();
+ VERIFY(!ot7);
+ optional<Thingy2> ot8 = std::experimental::nullopt;
+ VERIFY(!ot8);
+ optional<Thingy2> ot9 = {};
+ VERIFY(!ot9);
+ optional<Thingy2> ot10{std::experimental::nullopt};
+ VERIFY(!ot10);
+ optional<Thingy2> ot11;
+ ot11 = {};
+ VERIFY(!ot11);
+}
+
+struct Thingy3
+{
+ Thingy3(int) {}
+ template<class... Args,
+ std::enable_if_t<std::is_constructible<Widget, Args&&...>::value,
+ bool> = true>
+ explicit Thingy3(Args&&... args) {}
+ Thingy3(Widget) {}
+};
+
+void test08()
+{
+ optional<Thingy3> ot{optional<int>{}};
+ VERIFY(ot);
+ static_assert(!std::is_convertible<optional<int>,
+ optional<Thingy3>>::value);
+ optional<Thingy3> ot2{optional<short>{}};
+ VERIFY(ot2);
+ static_assert(!std::is_convertible<optional<short>,
+ optional<Thingy3>>::value);
+ optional<Thingy3> ot3{optional<optional<int>>{}};
+ VERIFY(!ot3);
+ static_assert(!std::is_convertible<optional<optional<int>>,
+ optional<Thingy3>>::value);
+ optional<Thingy3> ot4{optional<optional<short>>{}};
+ VERIFY(!ot4);
+ static_assert(!std::is_convertible<optional<optional<short>>,
+ optional<Thingy3>>::value);
+
+ optional<Thingy3> ot5{optional<Widget>{}};
+ VERIFY(!ot5);
+ optional<Thingy3> ot6 = optional<Widget>();
+ VERIFY(!ot6);
+
+ static_assert(!std::is_assignable<optional<Thingy3>&,
+ optional<int>>::value);
+ static_assert(!std::is_assignable<optional<Thingy3>&,
+ optional<short>>::value);
+ static_assert(!std::is_assignable<optional<Thingy3>&,
+ optional<optional<int>>>::value);
+ static_assert(!std::is_assignable<optional<Thingy3>&,
+ optional<optional<short>>>::value);
+ optional<Thingy3> ot7;
+ ot = optional<Widget>();
+ VERIFY(!ot7);
+ optional<Thingy3> ot8 = std::experimental::nullopt;
+ VERIFY(!ot8);
+ optional<Thingy3> ot9 = {};
+ VERIFY(!ot9);
+ optional<Thingy3> ot10{std::experimental::nullopt};
+ VERIFY(!ot10);
+ optional<Thingy3> ot11;
+ ot11 = {};
+ VERIFY(!ot11);
+}
+
+void test09()
+{
+ std::experimental::any a = 42;
+ optional<std::experimental::any> oa2 = a;
+ VERIFY(oa2);
+ VERIFY(std::experimental::any_cast<int>(*oa2) == 42);
+ optional<std::experimental::any> oa3 = oa2;
+ VERIFY(oa3);
+ VERIFY(std::experimental::any_cast<int>(*oa3) == 42);
+ optional<std::experimental::any> oa4{oa2};
+ VERIFY(oa4);
+ VERIFY(std::experimental::any_cast<int>(*oa4) == 42);
+ optional<std::experimental::any> oa5(oa2);
+ VERIFY(oa5);
+ VERIFY(std::experimental::any_cast<int>(*oa5) == 42);
+ optional<std::experimental::any> oa6;
+ VERIFY(!oa6);
+ optional<std::experimental::any> oa7 = oa6;
+ VERIFY(!oa7);
+ optional<std::experimental::any> oa8{oa6};
+ VERIFY(!oa8);
+ optional<std::experimental::any> oa9(oa6);
+ VERIFY(!oa9);
+}
+
+void test10()
+{
+ struct X {};
+ optional<int> oi(std::experimental::in_place);
+ oi = {};
+ VERIFY(bool(oi) == false);
+ optional<X> ot(std::experimental::in_place);
+ ot = {};
+ VERIFY(bool(ot) == false);
+ optional<int> oi2(std::experimental::in_place);
+ short int si = 6;
+ oi2 = si;
+}
+
+int main()
+{
+ test01();
+ test02();
+ test03();
+ test04();
+ test05();
+ test06();
+ test07();
+ test08();
+ test09();
+ test10();
+}
diff --git a/libstdc++-v3/testsuite/experimental/optional/assignment/5.cc b/libstdc++-v3/testsuite/experimental/optional/assignment/5.cc
index 0ee9740a6e6..42c1c27c886 100644
--- a/libstdc++-v3/testsuite/experimental/optional/assignment/5.cc
+++ b/libstdc++-v3/testsuite/experimental/optional/assignment/5.cc
@@ -19,6 +19,7 @@
// <http://www.gnu.org/licenses/>.
#include <experimental/optional>
+#include <vector>
#include <testsuite_hooks.h>
int counter = 0;
@@ -62,5 +63,15 @@ int main()
VERIFY( !o );
}
+ {
+ std::experimental::optional<std::vector<int>> ovi{{1, 2, 3}};
+ VERIFY(ovi->size() == 3);
+ VERIFY((*ovi)[0] == 1 && (*ovi)[1] == 2 && (*ovi)[2] == 3);
+ ovi = {4, 5, 6, 7};
+ VERIFY(ovi->size() == 4);
+ VERIFY((*ovi)[0] == 4 && (*ovi)[1] == 5 &&
+ (*ovi)[2] == 6 && (*ovi)[3] == 7);
+ }
+
VERIFY( counter == 0 );
}
diff --git a/libstdc++-v3/testsuite/experimental/optional/cons/77727.cc b/libstdc++-v3/testsuite/experimental/optional/cons/77727.cc
new file mode 100644
index 00000000000..efb2520a709
--- /dev/null
+++ b/libstdc++-v3/testsuite/experimental/optional/cons/77727.cc
@@ -0,0 +1,51 @@
+// { dg-options "-std=gnu++14" }
+// { dg-do run }
+
+// 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 moved_to of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <experimental/optional>
+#include <testsuite_hooks.h>
+
+
+struct NonTransferable
+{
+ int x;
+ NonTransferable(int x) : x(x) {}
+ NonTransferable(NonTransferable&&) = delete;
+ NonTransferable& operator=(NonTransferable&&) = delete;
+ operator int() {return x;}
+};
+
+int main()
+{
+ std::experimental::optional<int> oi;
+ std::experimental::optional<NonTransferable> ot(std::move(oi));
+ VERIFY(!ot);
+
+ std::experimental::optional<int> oi2;
+ std::experimental::optional<NonTransferable> ot2(oi2);
+ VERIFY(!ot);
+
+ std::experimental::optional<int> oi3{42};
+ std::experimental::optional<NonTransferable> ot3(std::move(oi3));
+ VERIFY(ot3 && *ot3 == 42);
+
+ std::experimental::optional<int> oi4{666};
+ std::experimental::optional<NonTransferable> ot4(oi4);
+ VERIFY(ot4 && *ot4 == 666);
+}
diff --git a/libstdc++-v3/testsuite/experimental/optional/cons/value.cc b/libstdc++-v3/testsuite/experimental/optional/cons/value.cc
index 123a89ede04..3006d11355f 100644
--- a/libstdc++-v3/testsuite/experimental/optional/cons/value.cc
+++ b/libstdc++-v3/testsuite/experimental/optional/cons/value.cc
@@ -255,4 +255,31 @@ int main()
std::experimental::optional<X> ox4;
ox4 = oi;
}
+
+ {
+ std::experimental::optional<std::experimental::optional<int>> ooi =
+ std::experimental::optional<int>();
+ VERIFY(bool(ooi));
+ ooi = std::experimental::optional<int>();
+ VERIFY(bool(ooi));
+ ooi = std::experimental::optional<int>(42);
+ VERIFY(bool(ooi));
+ VERIFY(bool(*ooi));
+ std::experimental::optional<std::experimental::optional<int>> ooi2 =
+ std::experimental::optional<short>();
+ VERIFY(bool(ooi2));
+ ooi2 = std::experimental::optional<short>();
+ VERIFY(bool(ooi2));
+ ooi2 = std::experimental::optional<short>(6);
+ VERIFY(bool(ooi2));
+ VERIFY(bool(*ooi2));
+ std::experimental::optional<std::experimental::optional<int>> ooi3 =
+ std::experimental::optional<int>(42);
+ VERIFY(bool(ooi3));
+ VERIFY(bool(*ooi3));
+ std::experimental::optional<std::experimental::optional<int>> ooi4 =
+ std::experimental::optional<short>(6);
+ VERIFY(bool(ooi4));
+ VERIFY(bool(*ooi4));
+ }
}