• 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
11 // <optional>
12 
13 // optional<T>& operator=(nullopt_t) noexcept;
14 
15 #include <experimental/optional>
16 #include <type_traits>
17 #include <cassert>
18 
19 using std::experimental::optional;
20 using std::experimental::nullopt_t;
21 using std::experimental::nullopt;
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()31 int main()
32 {
33     {
34         optional<int> opt;
35         static_assert(noexcept(opt = nullopt) == true, "");
36         opt = nullopt;
37         assert(static_cast<bool>(opt) == false);
38     }
39     {
40         optional<int> opt(3);
41         opt = nullopt;
42         assert(static_cast<bool>(opt) == false);
43     }
44     {
45         optional<X> opt;
46         static_assert(noexcept(opt = nullopt) == true, "");
47         assert(X::dtor_called == false);
48         opt = nullopt;
49         assert(X::dtor_called == false);
50         assert(static_cast<bool>(opt) == false);
51     }
52     {
53         X x;
54         {
55             optional<X> opt(x);
56             assert(X::dtor_called == false);
57             opt = nullopt;
58             assert(X::dtor_called == true);
59             assert(static_cast<bool>(opt) == false);
60         }
61     }
62 }
63