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