| 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 | // <mutex> |
| 10 | |
| 11 | // template <class Mutex> class unique_lock; |
| 12 | |
| 13 | // mutex_type *mutex() const; |
| 14 | |
| 15 | #include <cassert> |
| 16 | #include <memory> |
| 17 | #include <mutex> |
| 18 | |
| 19 | #include "checking_mutex.h" |
| 20 | #include "test_macros.h" |
| 21 | |
| 22 | #if TEST_STD_VER >= 11 |
| 23 | static_assert(noexcept(std::declval<std::unique_lock<checking_mutex>&>().mutex()), "" ); |
| 24 | #endif |
| 25 | |
| 26 | int main(int, char**) { |
| 27 | checking_mutex mux; |
| 28 | const std::unique_lock<checking_mutex> lock0; // Make sure `mutex()` is `const` |
| 29 | static_assert(std::is_same<decltype(lock0.mutex()), checking_mutex*>::value, "" ); |
| 30 | assert(lock0.mutex() == nullptr); |
| 31 | std::unique_lock<checking_mutex> lock1(mux); |
| 32 | assert(lock1.mutex() == std::addressof(mux)); |
| 33 | lock1.unlock(); |
| 34 | assert(lock1.mutex() == std::addressof(mux)); |
| 35 | |
| 36 | return 0; |
| 37 | } |
| 38 | |