op_bool.pass.cpp 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  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. // explicit operator bool() const noexcept;
  15. #include <shared_mutex>
  16. #include <cassert>
  17. std::shared_timed_mutex m;
  18. int main(int, char**)
  19. {
  20. std::shared_lock<std::shared_timed_mutex> lk0;
  21. assert(static_cast<bool>(lk0) == false);
  22. std::shared_lock<std::shared_timed_mutex> lk1(m);
  23. assert(static_cast<bool>(lk1) == true);
  24. lk1.unlock();
  25. assert(static_cast<bool>(lk1) == false);
  26. static_assert(noexcept(static_cast<bool>(lk0)), "explicit operator bool() must be noexcept");
  27. return 0;
  28. }