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.
Details
- Reviewers
Mordante ldionne var-const philnik - Group Reviewers
Restricted Project - Commits
- rGc115e760c25a: [libc++][test] Add tuple trivial destructor test
Diff Detail
- Repository
- rG LLVM Github Monorepo
Unit Tests
Event Timeline
LGTM!
libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/dtor.pass.cpp | ||
---|---|---|
48–56 | While you're at it, I would be nice if you can remove the unneeded whitespace in > >. |
Instead of moving this to a .compile.pass.cpp, I'd like to add an actual runtime test that the dtor does the right thing. Something like this:
struct TrackDtor { bool* dtorCalled_; constexpr explicit TrackDtor(bool* dtorCalled) : dtorCalled_(dtorCalled) { } TEST_CONSTEXPR_CXX20 ~TrackDtor() { *dtorCalled_ = true; } }; TEST_CONSTEXPR_CXX20 bool test() { bool called = false; { std::tuple<TrackDtor> tuple(TrackDtor(&called)); assert(!called); } assert(called); return true; } int main(int, char**) { test(); #if TEST_STD_VER > 20 static_assert(test()); #endif return 0; }
libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/dtor.pass.cpp | ||
---|---|---|
40 | This differs from @ldionne's suggestion. I wonder whether we should make sure the destruction of the temporary shouldn't increase the counter. Something like: struct TrackDtor { int* count_; constexpr explicit TrackDtor(int* count) : count_(count) {} constexpr TrackDtor(TrackDtor&& that) : count_(that.count_) { that.count_ = nullptr} TEST_CONSTEXPR_CXX20 ~TrackDtor() { if(coount_) ++*count_; } }; WDYT? | |
51 | Maybe move this to the other static_assert at line 33. |
Modify TrackDtor per Mordante's suggestion to make the intent of the test a bit clearer
libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/dtor.pass.cpp | ||
---|---|---|
48–55 | I assume you mean > 17 since it's constexpr in C++20. Fixed. |
libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/dtor.pass.cpp | ||
---|---|---|
48–55 | Oops. Yes I meant > 17. |
Can this test be constexpr in C++20?