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 { 27 constexpr int test() const {return 3;} 28 }; 29 30 struct Y 31 { 32 int test() const {return 2;} 33 }; 34 35 struct Z 36 { 37 const Z* operator&() const {return this;} 38 constexpr int test() const {return 1;} 39 }; 40 41 int main() 42 { 43 { 44 constexpr optional<X> opt(X{}); 45 static_assert(opt->test() == 3, ""); 46 } 47 { 48 constexpr optional<Y> opt(Y{}); 49 assert(opt->test() == 2); 50 } 51 { 52 constexpr optional<Z> opt(Z{}); 53 assert(opt->test() == 1); 54 #ifndef _LIBCPP_HAS_NO_BUILTIN_ADDRESSOF 55 static_assert(opt->test() == 1, ""); 56 #endif 57 } 58 #ifdef _LIBCPP_DEBUG 59 { 60 const optional<X> opt; 61 assert(opt->test() == 3); 62 assert(false); 63 } 64 #endif // _LIBCPP_DEBUG 65 } 66