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 
11 // <optional>
12 
13 // void reset() noexcept;
14 
15 #include <optional>
16 #include <type_traits>
17 #include <cassert>
18 
19 #include "test_macros.h"
20 
21 using std::optional;
22 
23 struct X
24 {
25     static bool dtor_called;
~XX26     ~X() {dtor_called = true;}
27 };
28 
29 bool X::dtor_called = false;
30 
main(int,char **)31 int main(int, char**)
32 {
33     {
34         optional<int> opt;
35         static_assert(noexcept(opt.reset()) == true, "");
36         opt.reset();
37         assert(static_cast<bool>(opt) == false);
38     }
39     {
40         optional<int> opt(3);
41         opt.reset();
42         assert(static_cast<bool>(opt) == false);
43     }
44     {
45         optional<X> opt;
46         static_assert(noexcept(opt.reset()) == true, "");
47         assert(X::dtor_called == false);
48         opt.reset();
49         assert(X::dtor_called == false);
50         assert(static_cast<bool>(opt) == false);
51     }
52     {
53         optional<X> opt(X{});
54         X::dtor_called = false;
55         opt.reset();
56         assert(X::dtor_called == true);
57         assert(static_cast<bool>(opt) == false);
58         X::dtor_called = false;
59     }
60 
61   return 0;
62 }
63