Home | History | Annotate | Download | only in optional.object.dtor
      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 // <optional>
     12 
     13 // ~optional();
     14 
     15 #include <optional>
     16 #include <type_traits>
     17 #include <cassert>
     18 
     19 using std::optional;
     20 
     21 struct PODType {
     22   int value;
     23   int value2;
     24 };
     25 
     26 class X
     27 {
     28 public:
     29     static bool dtor_called;
     30     X() = default;
     31     ~X() {dtor_called = true;}
     32 };
     33 
     34 bool X::dtor_called = false;
     35 
     36 int main()
     37 {
     38     {
     39         typedef int T;
     40         static_assert(std::is_trivially_destructible<T>::value, "");
     41         static_assert(std::is_trivially_destructible<optional<T>>::value, "");
     42         static_assert(std::is_literal_type<optional<T>>::value, "");
     43     }
     44     {
     45         typedef double T;
     46         static_assert(std::is_trivially_destructible<T>::value, "");
     47         static_assert(std::is_trivially_destructible<optional<T>>::value, "");
     48         static_assert(std::is_literal_type<optional<T>>::value, "");
     49     }
     50     {
     51         typedef PODType T;
     52         static_assert(std::is_trivially_destructible<T>::value, "");
     53         static_assert(std::is_trivially_destructible<optional<T>>::value, "");
     54         static_assert(std::is_literal_type<optional<T>>::value, "");
     55     }
     56     {
     57         typedef X T;
     58         static_assert(!std::is_trivially_destructible<T>::value, "");
     59         static_assert(!std::is_trivially_destructible<optional<T>>::value, "");
     60         static_assert(!std::is_literal_type<optional<T>>::value, "");
     61         {
     62             X x;
     63             optional<X> opt{x};
     64             assert(X::dtor_called == false);
     65         }
     66         assert(X::dtor_called == true);
     67     }
     68 }
     69