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