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++98, c++03, c++11, c++14 10 // <optional> 11 12 // ~optional(); 13 14 #include <optional> 15 #include <type_traits> 16 #include <cassert> 17 18 using std::optional; 19 20 struct PODType { 21 int value; 22 int value2; 23 }; 24 25 class X 26 { 27 public: 28 static bool dtor_called; 29 X() = default; 30 ~X() {dtor_called = true;} 31 }; 32 33 bool X::dtor_called = false; 34 35 int main(int, char**) 36 { 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 static_assert(std::is_literal_type<optional<T>>::value, ""); 42 } 43 { 44 typedef double T; 45 static_assert(std::is_trivially_destructible<T>::value, ""); 46 static_assert(std::is_trivially_destructible<optional<T>>::value, ""); 47 static_assert(std::is_literal_type<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 static_assert(std::is_literal_type<optional<T>>::value, ""); 54 } 55 { 56 typedef X T; 57 static_assert(!std::is_trivially_destructible<T>::value, ""); 58 static_assert(!std::is_trivially_destructible<optional<T>>::value, ""); 59 static_assert(!std::is_literal_type<optional<T>>::value, ""); 60 { 61 X x; 62 optional<X> opt{x}; 63 assert(X::dtor_called == false); 64 } 65 assert(X::dtor_called == true); 66 } 67 68 return 0; 69 } 70