dtor.pass.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // UNSUPPORTED: libcpp-has-no-threads
  10. // <thread>
  11. // class thread
  12. // ~thread();
  13. #include <thread>
  14. #include <new>
  15. #include <cstdlib>
  16. #include <cassert>
  17. #include "test_macros.h"
  18. class G
  19. {
  20. int alive_;
  21. public:
  22. static int n_alive;
  23. static bool op_run;
  24. G() : alive_(1) {++n_alive;}
  25. G(const G& g) : alive_(g.alive_) {++n_alive;}
  26. ~G() {alive_ = 0; --n_alive;}
  27. void operator()()
  28. {
  29. assert(alive_ == 1);
  30. assert(n_alive >= 1);
  31. op_run = true;
  32. }
  33. };
  34. int G::n_alive = 0;
  35. bool G::op_run = false;
  36. void f1()
  37. {
  38. std::_Exit(0);
  39. }
  40. int main(int, char**)
  41. {
  42. std::set_terminate(f1);
  43. {
  44. assert(G::n_alive == 0);
  45. assert(!G::op_run);
  46. G g;
  47. {
  48. std::thread t(g);
  49. std::this_thread::sleep_for(std::chrono::milliseconds(250));
  50. }
  51. }
  52. assert(false);
  53. return 0;
  54. }