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 // <optional>
11 
12 // ~optional();
13 
14 #include <experimental/optional>
15 #include <type_traits>
16 #include <cassert>
17 
18 #if _LIBCPP_STD_VER > 11
19 
20 using std::experimental::optional;
21 
22 class X
23 {
24 public:
25     static bool dtor_called;
26     X() = default;
~X()27     ~X() {dtor_called = true;}
28 };
29 
30 bool X::dtor_called = false;
31 
32 #endif  // _LIBCPP_STD_VER > 11
33 
main()34 int main()
35 {
36 #if _LIBCPP_STD_VER > 11
37     {
38         typedef int T;
39         static_assert(std::is_trivially_destructible<T>::value, "");
40         static_assert(std::is_trivially_destructible<optional<T>>::value, "");
41     }
42     {
43         typedef double T;
44         static_assert(std::is_trivially_destructible<T>::value, "");
45         static_assert(std::is_trivially_destructible<optional<T>>::value, "");
46     }
47     {
48         typedef X T;
49         static_assert(!std::is_trivially_destructible<T>::value, "");
50         static_assert(!std::is_trivially_destructible<optional<T>>::value, "");
51         {
52             X x;
53             optional<X> opt{x};
54             assert(X::dtor_called == false);
55         }
56         assert(X::dtor_called == true);
57     }
58 #endif  // _LIBCPP_STD_VER > 11
59 }
60