Page MenuHomePhabricator

[libc++][NFC] Make tuple dtor test compile test
Needs RevisionPublic

Authored by jloser on Sep 5 2021, 4:12 PM.

Details

Reviewers
Mordante
cjdb
Quuxplusone
ldionne
Group Reviewers
Restricted Project
Summary

dtor.pass.cpp means this file is compiled, linked, and executed but
all of its code is compile-time only. So, rename the file to
dtor.compile.pass.cpp so it only verifies that it compiles
successfully.

Clean up unused includes in the test file as well.

Diff Detail

Event Timeline

jloser requested review of this revision.Sep 5 2021, 4:12 PM
jloser created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptSep 5 2021, 4:12 PM
Herald added a reviewer: Restricted Project. · View Herald Transcript
Mordante accepted this revision as: Mordante.Sep 6 2021, 11:29 AM

LGTM!

libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/dtor.compile.pass.cpp
26–31

While you're at it, I would be nice if you can remove the unneeded whitespace in > >.

jloser updated this revision to Diff 370979.Sep 6 2021, 6:30 PM

[NFC] Remove extra whitespace from test

jloser marked an inline comment as done.Sep 6 2021, 6:35 PM
ldionne requested changes to this revision.Sep 7 2021, 9:36 AM
ldionne added a subscriber: ldionne.

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;
}
This revision now requires changes to proceed.Sep 7 2021, 9:36 AM