1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // <optional>
11 
12 // constexpr optional(nullopt_t) noexcept;
13 
14 #include <experimental/optional>
15 #include <type_traits>
16 #include <cassert>
17 
18 #if _LIBCPP_STD_VER > 11
19 
20 using std::experimental::optional;
21 using std::experimental::nullopt_t;
22 using std::experimental::nullopt;
23 
24 template <class Opt>
25 void
26 test_constexpr()
27 {
28     static_assert(noexcept(Opt(nullopt)), "");
29     constexpr Opt opt(nullopt);
30     static_assert(static_cast<bool>(opt) == false, "");
31 
32     struct test_constexpr_ctor
33         : public Opt
34     {
35         constexpr test_constexpr_ctor() {}
36     };
37 }
38 
39 template <class Opt>
40 void
41 test()
42 {
43     static_assert(noexcept(Opt(nullopt)), "");
44     Opt opt(nullopt);
45     assert(static_cast<bool>(opt) == false);
46 
47     struct test_constexpr_ctor
48         : public Opt
49     {
50         constexpr test_constexpr_ctor() {}
51     };
52 }
53 
54 struct X
55 {
56     X();
57 };
58 
59 #endif  // _LIBCPP_STD_VER > 11
60 
61 int main()
62 {
63 #if _LIBCPP_STD_VER > 11
64     test_constexpr<optional<int>>();
65     test_constexpr<optional<int*>>();
66     test<optional<X>>();
67 #endif  // _LIBCPP_STD_VER > 11
68 }
69