summaryrefslogtreecommitdiff
path: root/test/std/experimental/optional/optional.object/optional.object.ctor/move.pass.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/std/experimental/optional/optional.object/optional.object.ctor/move.pass.cpp')
-rw-r--r--test/std/experimental/optional/optional.object/optional.object.ctor/move.pass.cpp34
1 files changed, 32 insertions, 2 deletions
diff --git a/test/std/experimental/optional/optional.object/optional.object.ctor/move.pass.cpp b/test/std/experimental/optional/optional.object/optional.object.ctor/move.pass.cpp
index 851157f960f9..a8bb6e9c275c 100644
--- a/test/std/experimental/optional/optional.object/optional.object.ctor/move.pass.cpp
+++ b/test/std/experimental/optional/optional.object/optional.object.ctor/move.pass.cpp
@@ -8,7 +8,6 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++98, c++03, c++11
-// XFAIL: libcpp-no-exceptions
// <optional>
// optional(optional<T>&& rhs) noexcept(is_nothrow_move_constructible<T>::value);
@@ -17,6 +16,8 @@
#include <type_traits>
#include <cassert>
+#include "test_macros.h"
+
using std::experimental::optional;
template <class T>
@@ -26,16 +27,24 @@ test(optional<T>& rhs, bool is_going_to_throw = false)
static_assert(std::is_nothrow_move_constructible<optional<T>>::value ==
std::is_nothrow_move_constructible<T>::value, "");
bool rhs_engaged = static_cast<bool>(rhs);
+#ifdef TEST_HAS_NO_EXCEPTIONS
+ if (is_going_to_throw)
+ return;
+#else
try
+#endif
{
optional<T> lhs = std::move(rhs);
assert(is_going_to_throw == false);
assert(static_cast<bool>(lhs) == rhs_engaged);
}
+#ifndef TEST_HAS_NO_EXCEPTIONS
catch (int i)
{
assert(i == 6);
+ assert(is_going_to_throw);
}
+#endif
}
class X
@@ -68,12 +77,23 @@ public:
Z(Z&&)
{
if (++count == 2)
- throw 6;
+ TEST_THROW(6);
}
friend constexpr bool operator==(const Z& x, const Z& y) {return x.i_ == y.i_;}
};
+
+class ConstMovable
+{
+ int i_;
+public:
+ ConstMovable(int i) : i_(i) {}
+ ConstMovable(const ConstMovable&& x) : i_(x.i_) {}
+ ~ConstMovable() {i_ = 0;}
+ friend bool operator==(const ConstMovable& x, const ConstMovable& y) {return x.i_ == y.i_;}
+};
+
int main()
{
{
@@ -87,6 +107,11 @@ int main()
test(rhs);
}
{
+ typedef const int T;
+ optional<T> rhs(3);
+ test(rhs);
+ }
+ {
typedef X T;
optional<T> rhs;
test(rhs);
@@ -97,6 +122,11 @@ int main()
test(rhs);
}
{
+ typedef const ConstMovable T;
+ optional<T> rhs(ConstMovable(3));
+ test(rhs);
+ }
+ {
typedef Y T;
optional<T> rhs;
test(rhs);