//===----------------------------------------------------------------------===// // // The LLVM Compiler Infrastructure // // This file is dual licensed under the MIT and the University of Illinois Open // Source Licenses. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // // optional& operator=(nullopt_t) noexcept; #include #include #include #if _LIBCPP_STD_VER > 11 using std::experimental::optional; using std::experimental::nullopt_t; using std::experimental::nullopt; struct X { static bool dtor_called; ~X() {dtor_called = true;} }; bool X::dtor_called = false; #endif // _LIBCPP_STD_VER > 11 int main() { #if _LIBCPP_STD_VER > 11 { optional opt; static_assert(noexcept(opt = nullopt) == true, ""); opt = nullopt; assert(static_cast(opt) == false); } { optional opt(3); opt = nullopt; assert(static_cast(opt) == false); } { optional opt; static_assert(noexcept(opt = nullopt) == true, ""); assert(X::dtor_called == false); opt = nullopt; assert(X::dtor_called == false); assert(static_cast(opt) == false); } { X x; { optional opt(x); assert(X::dtor_called == false); opt = nullopt; assert(X::dtor_called == true); assert(static_cast(opt) == false); } } #endif // _LIBCPP_STD_VER > 11 }