dtor.pass.cpp 1.8 KB

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