dtor.pass.cpp 1.4 KB

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