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 const T& optional<T>::operator*() const;
13 
14 #ifdef _LIBCPP_DEBUG
15 #define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
16 #endif
17 
18 #include <experimental/optional>
19 #include <type_traits>
20 #include <cassert>
21 
22 #if _LIBCPP_STD_VER > 11
23 
24 using std::experimental::optional;
25 
26 struct X
27 {
testX28     constexpr int test() const {return 3;}
29 };
30 
31 struct Y
32 {
testY33     int test() const {return 2;}
34 };
35 
36 #endif  // _LIBCPP_STD_VER > 11
37 
main()38 int main()
39 {
40 #if _LIBCPP_STD_VER > 11
41     {
42         constexpr optional<X> opt(X{});
43         static_assert((*opt).test() == 3, "");
44     }
45     {
46         constexpr optional<Y> opt(Y{});
47         assert((*opt).test() == 2);
48     }
49 #ifdef _LIBCPP_DEBUG
50     {
51         const optional<X> opt;
52         assert((*opt).test() == 3);
53         assert(false);
54     }
55 #endif  // _LIBCPP_DEBUG
56 #endif  // _LIBCPP_STD_VER > 11
57 }
58