• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // UNSUPPORTED: c++98, c++03, c++11, c++14
11 
12 // <optional>
13 
14 // void reset() noexcept;
15 
16 #include <optional>
17 #include <type_traits>
18 #include <cassert>
19 
20 using std::optional;
21 
22 struct X
23 {
24     static bool dtor_called;
~XX25     ~X() {dtor_called = true;}
26 };
27 
28 bool X::dtor_called = false;
29 
main()30 int main()
31 {
32     {
33         optional<int> opt;
34         static_assert(noexcept(opt.reset()) == true, "");
35         opt.reset();
36         assert(static_cast<bool>(opt) == false);
37     }
38     {
39         optional<int> opt(3);
40         opt.reset();
41         assert(static_cast<bool>(opt) == false);
42     }
43     {
44         optional<X> opt;
45         static_assert(noexcept(opt.reset()) == true, "");
46         assert(X::dtor_called == false);
47         opt.reset();
48         assert(X::dtor_called == false);
49         assert(static_cast<bool>(opt) == false);
50     }
51     {
52         optional<X> opt(X{});
53         X::dtor_called = false;
54         opt.reset();
55         assert(X::dtor_called == true);
56         assert(static_cast<bool>(opt) == false);
57         X::dtor_called = false;
58     }
59 }
60