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