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