move_assign.pass.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. // UNSUPPORTED: c++98, c++03, c++11
  11. // XFAIL: dylib-has-no-shared_mutex
  12. // <shared_mutex>
  13. // template <class Mutex> class shared_lock;
  14. // shared_lock& operator=(shared_lock&& u);
  15. #include <shared_mutex>
  16. #include <cassert>
  17. #include "nasty_containers.hpp"
  18. int main(int, char**)
  19. {
  20. {
  21. typedef std::shared_timed_mutex M;
  22. M m0;
  23. M m1;
  24. std::shared_lock<M> lk0(m0);
  25. std::shared_lock<M> lk1(m1);
  26. lk1 = std::move(lk0);
  27. assert(lk1.mutex() == std::addressof(m0));
  28. assert(lk1.owns_lock() == true);
  29. assert(lk0.mutex() == nullptr);
  30. assert(lk0.owns_lock() == false);
  31. }
  32. {
  33. typedef nasty_mutex M;
  34. M m0;
  35. M m1;
  36. std::shared_lock<M> lk0(m0);
  37. std::shared_lock<M> lk1(m1);
  38. lk1 = std::move(lk0);
  39. assert(lk1.mutex() == std::addressof(m0));
  40. assert(lk1.owns_lock() == true);
  41. assert(lk0.mutex() == nullptr);
  42. assert(lk0.owns_lock() == false);
  43. }
  44. return 0;
  45. }