1 //===----------------------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 // UNSUPPORTED: c++03, c++11, c++14 10 // <optional> 11 12 // optional<T>& operator=(nullopt_t) noexcept; 13 14 #include <optional> 15 #include <type_traits> 16 #include <cassert> 17 18 #include "test_macros.h" 19 #include "archetypes.h" 20 21 using std::optional; 22 using std::nullopt_t; 23 using std::nullopt; 24 main(int,char **)25int main(int, char**) 26 { 27 { 28 optional<int> opt; 29 static_assert(noexcept(opt = nullopt) == true, ""); 30 opt = nullopt; 31 assert(static_cast<bool>(opt) == false); 32 } 33 { 34 optional<int> opt(3); 35 opt = nullopt; 36 assert(static_cast<bool>(opt) == false); 37 } 38 using TT = TestTypes::TestType; 39 TT::reset(); 40 { 41 optional<TT> opt; 42 static_assert(noexcept(opt = nullopt) == true, ""); 43 assert(TT::destroyed == 0); 44 opt = nullopt; 45 assert(TT::constructed == 0); 46 assert(TT::alive == 0); 47 assert(TT::destroyed == 0); 48 assert(static_cast<bool>(opt) == false); 49 } 50 assert(TT::alive == 0); 51 assert(TT::destroyed == 0); 52 TT::reset(); 53 { 54 optional<TT> opt(42); 55 assert(TT::destroyed == 0); 56 TT::reset_constructors(); 57 opt = nullopt; 58 assert(TT::constructed == 0); 59 assert(TT::alive == 0); 60 assert(TT::destroyed == 1); 61 assert(static_cast<bool>(opt) == false); 62 } 63 assert(TT::alive == 0); 64 assert(TT::destroyed == 1); 65 TT::reset(); 66 67 return 0; 68 } 69