1 //===----------------------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 // UNSUPPORTED: c++03, c++11, c++14 10 // <optional> 11 12 // ~optional(); 13 14 #include <optional> 15 #include <type_traits> 16 #include <cassert> 17 18 #include "test_macros.h" 19 20 using std::optional; 21 22 struct PODType { 23 int value; 24 int value2; 25 }; 26 27 class X 28 { 29 public: 30 static bool dtor_called; 31 X() = default; 32 ~X() {dtor_called = true;} 33 }; 34 35 bool X::dtor_called = false; 36 37 int main(int, char**) 38 { 39 { 40 typedef int T; 41 static_assert(std::is_trivially_destructible<T>::value, ""); 42 static_assert(std::is_trivially_destructible<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 } 49 { 50 typedef PODType T; 51 static_assert(std::is_trivially_destructible<T>::value, ""); 52 static_assert(std::is_trivially_destructible<optional<T>>::value, ""); 53 } 54 { 55 typedef X T; 56 static_assert(!std::is_trivially_destructible<T>::value, ""); 57 static_assert(!std::is_trivially_destructible<optional<T>>::value, ""); 58 { 59 X x; 60 optional<X> opt{x}; 61 assert(X::dtor_called == false); 62 } 63 assert(X::dtor_called == true); 64 } 65 66 return 0; 67 } 68