• 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 // T& optional<T>::operator*();
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;}
testX28     int test() {return 4;}
29 };
30 
main()31 int main()
32 {
33     {
34         optional<X> opt(X{});
35         assert((*opt).test() == 4);
36     }
37 #ifdef _LIBCPP_DEBUG
38     {
39         optional<X> opt;
40         assert((*opt).test() == 3);
41         assert(false);
42     }
43 #endif  // _LIBCPP_DEBUG
44 }
45