1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // UNSUPPORTED: c++98, c++03, c++11
11 // XFAIL: libcpp-no-exceptions
14 // optional<T>& operator=(const optional<T>& rhs);
16 #include <experimental/optional>
17 #include <type_traits>
20 using std::experimental::optional;
24 static bool throw_now;
34 bool X::throw_now = false;
40 constexpr optional<int> opt2;
42 static_assert(static_cast<bool>(opt2) == false, "");
43 assert(static_cast<bool>(opt) == static_cast<bool>(opt2));
47 constexpr optional<int> opt2(2);
49 static_assert(static_cast<bool>(opt2) == true, "");
50 static_assert(*opt2 == 2, "");
51 assert(static_cast<bool>(opt) == static_cast<bool>(opt2));
52 assert(*opt == *opt2);
56 constexpr optional<int> opt2;
58 static_assert(static_cast<bool>(opt2) == false, "");
59 assert(static_cast<bool>(opt) == static_cast<bool>(opt2));
63 constexpr optional<int> opt2(2);
65 static_assert(static_cast<bool>(opt2) == true, "");
66 static_assert(*opt2 == 2, "");
67 assert(static_cast<bool>(opt) == static_cast<bool>(opt2));
68 assert(*opt == *opt2);
72 optional<X> opt2(X{});
73 assert(static_cast<bool>(opt2) == true);
83 assert(static_cast<bool>(opt) == false);