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 optional(nullopt_t) noexcept; 14 15 #include <experimental/optional> 16 #include <type_traits> 17 #include <cassert> 18 19 using std::experimental::optional; 20 using std::experimental::nullopt_t; 21 using std::experimental::nullopt; 22 23 template <class Opt> 24 void test_constexpr()25test_constexpr() 26 { 27 static_assert(noexcept(Opt(nullopt)), ""); 28 constexpr Opt opt(nullopt); 29 static_assert(static_cast<bool>(opt) == false, ""); 30 31 struct test_constexpr_ctor 32 : public Opt 33 { 34 constexpr test_constexpr_ctor() {} 35 }; 36 } 37 38 template <class Opt> 39 void test()40test() 41 { 42 static_assert(noexcept(Opt(nullopt)), ""); 43 Opt opt(nullopt); 44 assert(static_cast<bool>(opt) == false); 45 46 struct test_constexpr_ctor 47 : public Opt 48 { 49 constexpr test_constexpr_ctor() {} 50 }; 51 } 52 53 struct X 54 { 55 X(); 56 }; 57 main()58int main() 59 { 60 test_constexpr<optional<int>>(); 61 test_constexpr<optional<int*>>(); 62 test<optional<X>>(); 63 } 64