• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // UNSUPPORTED: c++98, c++03, c++11
11 // <optional>
12 
13 // constexpr const T& optional<T>::operator*() const;
14 
15 #ifdef _LIBCPP_DEBUG
16 #define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
17 #endif
18 
19 #include <experimental/optional>
20 #include <type_traits>
21 #include <cassert>
22 
23 using std::experimental::optional;
24 
25 struct X
26 {
testX27     constexpr int test() const {return 3;}
28 };
29 
30 struct Y
31 {
testY32     int test() const {return 2;}
33 };
34 
main()35 int main()
36 {
37     {
38         constexpr optional<X> opt(X{});
39         static_assert((*opt).test() == 3, "");
40     }
41     {
42         constexpr optional<Y> opt(Y{});
43         assert((*opt).test() == 2);
44     }
45 #ifdef _LIBCPP_DEBUG
46     {
47         const optional<X> opt;
48         assert((*opt).test() == 3);
49         assert(false);
50     }
51 #endif  // _LIBCPP_DEBUG
52 }
53