[libcxx-commits] [libcxx] c115e76 - [libc++][test] Add tuple trivial destructor test

Joe Loser via libcxx-commits libcxx-commits at lists.llvm.org
Sat Jun 11 17:12:08 PDT 2022


Author: Joe Loser
Date: 2022-06-11T18:11:04-06:00
New Revision: c115e760c25a45e0d045ebb51d758a5386a9ce94

URL: https://github.com/llvm/llvm-project/commit/c115e760c25a45e0d045ebb51d758a5386a9ce94
DIFF: https://github.com/llvm/llvm-project/commit/c115e760c25a45e0d045ebb51d758a5386a9ce94.diff

LOG: [libc++][test] Add tuple trivial destructor test

There is only compile-time tests in `dtor.pass.cpp`, so it could be made a
`dtor.compile.pass.cpp`. Instead, add a runtime test for testing the trivial
destructor behavior for `tuple`.

Differential Revision: https://reviews.llvm.org/D109298

Added: 
    

Modified: 
    libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/dtor.pass.cpp

Removed: 
    


################################################################################
diff  --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/dtor.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/dtor.pass.cpp
index 44a7e0dfb470e..caebaca5c3953 100644
--- a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/dtor.pass.cpp
+++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/dtor.pass.cpp
@@ -25,18 +25,37 @@
 
 #include "test_macros.h"
 
+struct TrackDtor {
+   int* count_;
+   constexpr explicit TrackDtor(int* count) : count_(count) {}
+   TEST_CONSTEXPR_CXX14 TrackDtor(TrackDtor&& that) : count_(that.count_) { that.count_ = nullptr; }
+   TEST_CONSTEXPR_CXX20 ~TrackDtor() { if(count_) ++*count_; }
+};
+static_assert(!std::is_trivially_destructible<TrackDtor>::value, "");
+
+static_assert(std::is_trivially_destructible<std::tuple<>>::value, "");
+static_assert(std::is_trivially_destructible<std::tuple<void*>>::value, "");
+static_assert(std::is_trivially_destructible<std::tuple<int, float>>::value, "");
+static_assert(!std::is_trivially_destructible<std::tuple<std::string>>::value, "");
+static_assert(!std::is_trivially_destructible<std::tuple<int, std::string>>::value, "");
+
+TEST_CONSTEXPR_CXX20 bool test() {
+  int count = 0;
+  {
+    std::tuple<TrackDtor> tuple{TrackDtor(&count)};
+    assert(count == 0);
+  }
+  assert(count == 1);
+
+  return true;
+}
+
 int main(int, char**)
 {
-  static_assert(std::is_trivially_destructible<
-      std::tuple<> >::value, "");
-  static_assert(std::is_trivially_destructible<
-      std::tuple<void*> >::value, "");
-  static_assert(std::is_trivially_destructible<
-      std::tuple<int, float> >::value, "");
-  static_assert(!std::is_trivially_destructible<
-      std::tuple<std::string> >::value, "");
-  static_assert(!std::is_trivially_destructible<
-      std::tuple<int, std::string> >::value, "");
+  test();
+#if TEST_STD_VER > 17
+  static_assert(test());
+#endif
 
   return 0;
 }


        


More information about the libcxx-commits mailing list