default.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() 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(std::is_nothrow_default_constructible<Opt>::value, ""); 25 constexpr Opt opt; 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} 35 36template <class Opt> 37void 38test() 39{ 40 static_assert(std::is_nothrow_default_constructible<Opt>::value, ""); 41 Opt opt; 42 assert(static_cast<bool>(opt) == false); 43 44 struct test_constexpr_ctor 45 : public Opt 46 { 47 constexpr test_constexpr_ctor() {} 48 }; 49} 50 51struct X 52{ 53 X(); 54}; 55 56#endif // _LIBCPP_STD_VER > 11 57 58int main() 59{ 60#if _LIBCPP_STD_VER > 11 61 test_constexpr<std::optional<int>>(); 62 test_constexpr<std::optional<int*>>(); 63 test<std::optional<X>>(); 64#endif // _LIBCPP_STD_VER > 11 65} 66