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