summaryrefslogtreecommitdiff
path: root/test/std/thread/thread.mutex/thread.lock
diff options
context:
space:
mode:
Diffstat (limited to 'test/std/thread/thread.mutex/thread.lock')
-rw-r--r--test/std/thread/thread.mutex/thread.lock/thread.lock.guard/mutex.fail.cpp32
-rw-r--r--test/std/thread/thread.mutex/thread.lock/thread.lock.guard/variadic_adopt_lock.pass.cpp62
-rw-r--r--test/std/thread/thread.mutex/thread.lock/thread.lock.guard/variadic_assign.fail.cpp44
-rw-r--r--test/std/thread/thread.mutex/thread.lock/thread.lock.guard/variadic_copy.fail.cpp41
-rw-r--r--test/std/thread/thread.mutex/thread.lock/thread.lock.guard/variadic_mutex.fail.cpp47
-rw-r--r--test/std/thread/thread.mutex/thread.lock/thread.lock.guard/variadic_mutex.pass.cpp115
-rw-r--r--test/std/thread/thread.mutex/thread.lock/thread.lock.guard/variadic_mutex_cxx03.pass.cpp21
-rw-r--r--test/std/thread/thread.mutex/thread.lock/thread.lock.guard/variadic_types.pass.cpp78
-rw-r--r--test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/copy_assign.fail.cpp9
-rw-r--r--test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/copy_ctor.fail.cpp7
-rw-r--r--test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/move_assign.pass.cpp26
-rw-r--r--test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/move_ctor.pass.cpp22
-rw-r--r--test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_adopt_lock.pass.cpp20
-rw-r--r--test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_defer_lock.pass.cpp17
-rw-r--r--test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/copy_assign.fail.cpp12
-rw-r--r--test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/copy_ctor.fail.cpp10
-rw-r--r--test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/move_assign.pass.cpp27
-rw-r--r--test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/move_ctor.pass.cpp23
-rw-r--r--test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/mutex_adopt_lock.pass.cpp18
-rw-r--r--test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/mutex_defer_lock.pass.cpp17
20 files changed, 564 insertions, 84 deletions
diff --git a/test/std/thread/thread.mutex/thread.lock/thread.lock.guard/mutex.fail.cpp b/test/std/thread/thread.mutex/thread.lock/thread.lock.guard/mutex.fail.cpp
index 246eb935c995d..520c9730bdf7a 100644
--- a/test/std/thread/thread.mutex/thread.lock/thread.lock.guard/mutex.fail.cpp
+++ b/test/std/thread/thread.mutex/thread.lock/thread.lock.guard/mutex.fail.cpp
@@ -7,6 +7,8 @@
//
//===----------------------------------------------------------------------===//
+// UNSUPPORTED: libcpp-has-no-threads
+
// <mutex>
// template <class Mutex> class lock_guard;
@@ -14,35 +16,9 @@
// explicit lock_guard(mutex_type& m);
#include <mutex>
-#include <thread>
-#include <cstdlib>
-#include <cassert>
-
-std::mutex m;
-
-typedef std::chrono::system_clock Clock;
-typedef Clock::time_point time_point;
-typedef Clock::duration duration;
-typedef std::chrono::milliseconds ms;
-typedef std::chrono::nanoseconds ns;
-
-void f()
-{
- time_point t0 = Clock::now();
- time_point t1;
- {
- std::lock_guard<std::mutex> lg = m;
- t1 = Clock::now();
- }
- ns d = t1 - t0 - ms(250);
- assert(d < ns(2500000)); // within 2.5ms
-}
int main()
{
- m.lock();
- std::thread t(f);
- std::this_thread::sleep_for(ms(250));
- m.unlock();
- t.join();
+ std::mutex m;
+ std::lock_guard<std::mutex> lg = m; // expected-error{{no viable conversion}}
}
diff --git a/test/std/thread/thread.mutex/thread.lock/thread.lock.guard/variadic_adopt_lock.pass.cpp b/test/std/thread/thread.mutex/thread.lock/thread.lock.guard/variadic_adopt_lock.pass.cpp
new file mode 100644
index 0000000000000..840af6788d04f
--- /dev/null
+++ b/test/std/thread/thread.mutex/thread.lock/thread.lock.guard/variadic_adopt_lock.pass.cpp
@@ -0,0 +1,62 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// UNSUPPORTED: libcpp-has-no-threads
+// UNSUPPORTED: c++98, c++03
+
+// <mutex>
+
+// template <class ...Mutex> class lock_guard;
+
+// lock_guard(Mutex&..., adopt_lock_t);
+
+#define _LIBCPP_ABI_VARIADIC_LOCK_GUARD
+#include <mutex>
+#include <cassert>
+
+struct TestMutex {
+ bool locked = false;
+ TestMutex() = default;
+
+ void lock() { assert(!locked); locked = true; }
+ bool try_lock() { if (locked) return false; locked = true; return true; }
+ void unlock() { assert(locked); locked = false; }
+
+ TestMutex(TestMutex const&) = delete;
+ TestMutex& operator=(TestMutex const&) = delete;
+};
+
+int main()
+{
+ {
+ using LG = std::lock_guard<>;
+ LG lg(std::adopt_lock);
+ }
+ {
+ TestMutex m1, m2;
+ using LG = std::lock_guard<TestMutex, TestMutex>;
+ m1.lock(); m2.lock();
+ {
+ LG lg(m1, m2, std::adopt_lock);
+ assert(m1.locked && m2.locked);
+ }
+ assert(!m1.locked && !m2.locked);
+ }
+ {
+ TestMutex m1, m2, m3;
+ using LG = std::lock_guard<TestMutex, TestMutex, TestMutex>;
+ m1.lock(); m2.lock(); m3.lock();
+ {
+ LG lg(m1, m2, m3, std::adopt_lock);
+ assert(m1.locked && m2.locked && m3.locked);
+ }
+ assert(!m1.locked && !m2.locked && !m3.locked);
+ }
+
+}
diff --git a/test/std/thread/thread.mutex/thread.lock/thread.lock.guard/variadic_assign.fail.cpp b/test/std/thread/thread.mutex/thread.lock/thread.lock.guard/variadic_assign.fail.cpp
new file mode 100644
index 0000000000000..18193e000edc7
--- /dev/null
+++ b/test/std/thread/thread.mutex/thread.lock/thread.lock.guard/variadic_assign.fail.cpp
@@ -0,0 +1,44 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: libcpp-has-no-threads
+// UNSUPPORTED: c++98, c++03
+
+// <mutex>
+
+// template <class ...Mutex> class lock_guard;
+
+// lock_guard& operator=(lock_guard const&) = delete;
+
+#define _LIBCPP_ABI_VARIADIC_LOCK_GUARD
+#include <mutex>
+
+int main()
+{
+ using M = std::mutex;
+ M m0, m1, m2;
+ M om0, om1, om2;
+ {
+ using LG = std::lock_guard<>;
+ LG lg1, lg2;
+ lg1 = lg2; // expected-error{{overload resolution selected deleted operator '='}}
+ }
+ {
+ using LG = std::lock_guard<M, M>;
+ LG lg1(m0, m1);
+ LG lg2(om0, om1);
+ lg1 = lg2; // expected-error{{overload resolution selected deleted operator '='}}
+ }
+ {
+ using LG = std::lock_guard<M, M, M>;
+ LG lg1(m0, m1, m2);
+ LG lg2(om0, om1, om2);
+ lg1 = lg2; // expected-error{{overload resolution selected deleted operator '='}}
+ }
+}
diff --git a/test/std/thread/thread.mutex/thread.lock/thread.lock.guard/variadic_copy.fail.cpp b/test/std/thread/thread.mutex/thread.lock/thread.lock.guard/variadic_copy.fail.cpp
new file mode 100644
index 0000000000000..6dc37e970fb60
--- /dev/null
+++ b/test/std/thread/thread.mutex/thread.lock/thread.lock.guard/variadic_copy.fail.cpp
@@ -0,0 +1,41 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: libcpp-has-no-threads
+// UNSUPPORTED: c++98, c++03
+
+// <mutex>
+
+// template <class ...Mutex> class lock_guard;
+
+// lock_guard(lock_guard const&) = delete;
+
+#define _LIBCPP_ABI_VARIADIC_LOCK_GUARD
+#include <mutex>
+
+int main()
+{
+ using M = std::mutex;
+ M m0, m1, m2;
+ {
+ using LG = std::lock_guard<>;
+ const LG Orig;
+ LG Copy(Orig); // expected-error{{call to deleted constructor of 'LG'}}
+ }
+ {
+ using LG = std::lock_guard<M, M>;
+ const LG Orig(m0, m1);
+ LG Copy(Orig); // expected-error{{call to deleted constructor of 'LG'}}
+ }
+ {
+ using LG = std::lock_guard<M, M, M>;
+ const LG Orig(m0, m1, m2);
+ LG Copy(Orig); // expected-error{{call to deleted constructor of 'LG'}}
+ }
+}
diff --git a/test/std/thread/thread.mutex/thread.lock/thread.lock.guard/variadic_mutex.fail.cpp b/test/std/thread/thread.mutex/thread.lock/thread.lock.guard/variadic_mutex.fail.cpp
new file mode 100644
index 0000000000000..866538a2834f5
--- /dev/null
+++ b/test/std/thread/thread.mutex/thread.lock/thread.lock.guard/variadic_mutex.fail.cpp
@@ -0,0 +1,47 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: libcpp-has-no-threads
+// UNSUPPORTED: c++98, c++03
+
+// <mutex>
+
+// template <class ...Mutex> class lock_guard;
+
+// explicit lock_guard(Mutex&...);
+
+#define _LIBCPP_ABI_VARIADIC_LOCK_GUARD
+#include <mutex>
+
+template <class LG>
+void test_conversion(LG) {}
+
+int main()
+{
+ using M = std::mutex;
+ M m0, m1, m2;
+ M n0, n1, n2;
+ {
+ using LG = std::lock_guard<>;
+ LG lg = {}; // expected-error{{chosen constructor is explicit in copy-initialization}}
+ test_conversion<LG>({}); // expected-error{{no matching function for call}}
+ ((void)lg);
+ }
+ {
+ using LG = std::lock_guard<M, M>;
+ LG lg = {m0, m1}; // expected-error{{chosen constructor is explicit in copy-initialization}}
+ test_conversion<LG>({n0, n1}); // expected-error{{no matching function for call}}
+ ((void)lg);
+ }
+ {
+ using LG = std::lock_guard<M, M, M>;
+ LG lg = {m0, m1, m2}; // expected-error{{chosen constructor is explicit in copy-initialization}}
+ test_conversion<LG>({n0, n1, n2}); // expected-error{{no matching function for call}}
+ }
+}
diff --git a/test/std/thread/thread.mutex/thread.lock/thread.lock.guard/variadic_mutex.pass.cpp b/test/std/thread/thread.mutex/thread.lock/thread.lock.guard/variadic_mutex.pass.cpp
new file mode 100644
index 0000000000000..4910d837cae32
--- /dev/null
+++ b/test/std/thread/thread.mutex/thread.lock/thread.lock.guard/variadic_mutex.pass.cpp
@@ -0,0 +1,115 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// UNSUPPORTED: libcpp-has-no-threads
+// UNSUPPORTED: c++98, c++03
+
+// <mutex>
+
+// template <class ...Mutex> class lock_guard;
+
+// explicit lock_guard(mutex_type& m);
+
+#define _LIBCPP_ABI_VARIADIC_LOCK_GUARD
+#include <mutex>
+#include <cassert>
+
+#include "test_macros.h"
+
+struct TestMutex {
+ bool locked = false;
+ TestMutex() = default;
+ ~TestMutex() { assert(!locked); }
+
+ void lock() { assert(!locked); locked = true; }
+ bool try_lock() { if (locked) return false; locked = true; return true; }
+ void unlock() { assert(locked); locked = false; }
+
+ TestMutex(TestMutex const&) = delete;
+ TestMutex& operator=(TestMutex const&) = delete;
+};
+
+#if !defined(TEST_HAS_NO_EXCEPTIONS)
+struct TestMutexThrows {
+ bool locked = false;
+ bool throws_on_lock = false;
+
+ TestMutexThrows() = default;
+ ~TestMutexThrows() { assert(!locked); }
+
+ void lock() {
+ assert(!locked);
+ if (throws_on_lock) {
+ throw 42;
+ }
+ locked = true;
+ }
+
+ bool try_lock() {
+ if (locked) return false;
+ lock();
+ return true;
+ }
+
+ void unlock() { assert(locked); locked = false; }
+
+ TestMutexThrows(TestMutexThrows const&) = delete;
+ TestMutexThrows& operator=(TestMutexThrows const&) = delete;
+};
+#endif // !defined(TEST_HAS_NO_EXCEPTIONS)
+
+int main()
+{
+ {
+ using LG = std::lock_guard<>;
+ LG lg;
+ }
+ {
+ using LG = std::lock_guard<TestMutex, TestMutex>;
+ TestMutex m1, m2;
+ {
+ LG lg(m1, m2);
+ assert(m1.locked && m2.locked);
+ }
+ assert(!m1.locked && !m2.locked);
+ }
+ {
+ using LG = std::lock_guard<TestMutex, TestMutex, TestMutex>;
+ TestMutex m1, m2, m3;
+ {
+ LG lg(m1, m2, m3);
+ assert(m1.locked && m2.locked && m3.locked);
+ }
+ assert(!m1.locked && !m2.locked && !m3.locked);
+ }
+#if !defined(TEST_HAS_NO_EXCEPTIONS)
+ {
+ using MT = TestMutexThrows;
+ using LG = std::lock_guard<MT, MT>;
+ MT m1, m2;
+ m1.throws_on_lock = true;
+ try {
+ LG lg(m1, m2);
+ assert(false);
+ } catch (int) {}
+ assert(!m1.locked && !m2.locked);
+ }
+ {
+ using MT = TestMutexThrows;
+ using LG = std::lock_guard<MT, MT, MT>;
+ MT m1, m2, m3;
+ m2.throws_on_lock = true;
+ try {
+ LG lg(m1, m2, m3);
+ assert(false);
+ } catch (int) {}
+ assert(!m1.locked && !m2.locked && !m3.locked);
+ }
+#endif
+}
diff --git a/test/std/thread/thread.mutex/thread.lock/thread.lock.guard/variadic_mutex_cxx03.pass.cpp b/test/std/thread/thread.mutex/thread.lock/thread.lock.guard/variadic_mutex_cxx03.pass.cpp
new file mode 100644
index 0000000000000..3c134e0b88615
--- /dev/null
+++ b/test/std/thread/thread.mutex/thread.lock/thread.lock.guard/variadic_mutex_cxx03.pass.cpp
@@ -0,0 +1,21 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// UNSUPPORTED: libcpp-has-no-threads
+
+// <mutex>
+
+// template <class ...Mutex> class lock_guard;
+
+// Test that the variadic lock guard implementation compiles in all standard
+// dialects, including C++03, even though it is forward declared using
+// variadic templates.
+
+#define _LIBCPP_ABI_VARIADIC_LOCK_GUARD
+#include "mutex.pass.cpp" // Use the existing non-variadic test
diff --git a/test/std/thread/thread.mutex/thread.lock/thread.lock.guard/variadic_types.pass.cpp b/test/std/thread/thread.mutex/thread.lock/thread.lock.guard/variadic_types.pass.cpp
new file mode 100644
index 0000000000000..2b06742a673e6
--- /dev/null
+++ b/test/std/thread/thread.mutex/thread.lock/thread.lock.guard/variadic_types.pass.cpp
@@ -0,0 +1,78 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// UNSUPPORTED: libcpp-has-no-threads
+// UNSUPPORTED: c++98, c++03
+
+// <mutex>
+
+// template <class Mutex>
+// class lock_guard
+// {
+// public:
+// typedef Mutex mutex_type;
+// ...
+// };
+
+#define _LIBCPP_ABI_VARIADIC_LOCK_GUARD
+#include <mutex>
+#include <type_traits>
+
+struct NAT {};
+
+template <class LG>
+auto test_typedef(int) -> typename LG::mutex_type;
+
+template <class LG>
+auto test_typedef(...) -> NAT;
+
+template <class LG>
+constexpr bool has_mutex_type() {
+ return !std::is_same<decltype(test_typedef<LG>(0)), NAT>::value;
+}
+
+int main()
+{
+ {
+ using T = std::lock_guard<>;
+ static_assert(!has_mutex_type<T>(), "");
+ }
+ {
+ using M1 = std::mutex;
+ using T = std::lock_guard<M1>;
+ static_assert(std::is_same<T::mutex_type, M1>::value, "");
+ }
+ {
+ using M1 = std::recursive_mutex;
+ using T = std::lock_guard<M1>;
+ static_assert(std::is_same<T::mutex_type, M1>::value, "");
+ }
+ {
+ using M1 = std::mutex;
+ using M2 = std::recursive_mutex;
+ using T = std::lock_guard<M1, M2>;
+ static_assert(!has_mutex_type<T>(), "");
+ }
+ {
+ using M1 = std::mutex;
+ using M2 = std::recursive_mutex;
+ using T = std::lock_guard<M1, M1, M2>;
+ static_assert(!has_mutex_type<T>(), "");
+ }
+ {
+ using M1 = std::mutex;
+ using T = std::lock_guard<M1, M1>;
+ static_assert(!has_mutex_type<T>(), "");
+ }
+ {
+ using M1 = std::recursive_mutex;
+ using T = std::lock_guard<M1, M1, M1>;
+ static_assert(!has_mutex_type<T>(), "");
+ }
+}
diff --git a/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/copy_assign.fail.cpp b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/copy_assign.fail.cpp
index 446807f3f3335..79f43e860ca2f 100644
--- a/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/copy_assign.fail.cpp
+++ b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/copy_assign.fail.cpp
@@ -7,6 +7,7 @@
//
//===----------------------------------------------------------------------===//
+// UNSUPPORTED: c++98, c++03, c++11
// <shared_mutex>
// template <class Mutex> class shared_lock;
@@ -15,20 +16,12 @@
#include <shared_mutex>
-#if _LIBCPP_STD_VER > 11
-
std::shared_timed_mutex m0;
std::shared_timed_mutex m1;
-#endif // _LIBCPP_STD_VER > 11
-
int main()
{
-#if _LIBCPP_STD_VER > 11
std::shared_lock<std::shared_timed_mutex> lk0(m0);
std::shared_lock<std::shared_timed_mutex> lk1(m1);
lk1 = lk0;
-#else
-# error
-#endif // _LIBCPP_STD_VER > 11
}
diff --git a/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/copy_ctor.fail.cpp b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/copy_ctor.fail.cpp
index 370c1fa4e3361..d6bf57947afe0 100644
--- a/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/copy_ctor.fail.cpp
+++ b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/copy_ctor.fail.cpp
@@ -7,6 +7,7 @@
//
//===----------------------------------------------------------------------===//
+// UNSUPPORTED: c++98, c++03, c++11
// <shared_mutex>
// template <class Mutex> class shared_lock;
@@ -15,16 +16,10 @@
#include <shared_mutex>
-#if _LIBCPP_STD_VER > 11
std::shared_timed_mutex m;
-#endif // _LIBCPP_STD_VER > 11
int main()
{
-#if _LIBCPP_STD_VER > 11
std::shared_lock<std::shared_timed_mutex> lk0(m);
std::shared_lock<std::shared_timed_mutex> lk = lk0;
-#else
-# error
-#endif // _LIBCPP_STD_VER > 11
}
diff --git a/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/move_assign.pass.cpp b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/move_assign.pass.cpp
index 15c193c60b5d3..bd707bb90ce10 100644
--- a/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/move_assign.pass.cpp
+++ b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/move_assign.pass.cpp
@@ -18,17 +18,33 @@
#include <shared_mutex>
#include <cassert>
+#include "nasty_containers.hpp"
-std::shared_timed_mutex m0;
-std::shared_timed_mutex m1;
int main()
{
- std::shared_lock<std::shared_timed_mutex> lk0(m0);
- std::shared_lock<std::shared_timed_mutex> lk1(m1);
+ {
+ typedef std::shared_timed_mutex M;
+ M m0;
+ M m1;
+ std::shared_lock<M> lk0(m0);
+ std::shared_lock<M> lk1(m1);
lk1 = std::move(lk0);
- assert(lk1.mutex() == &m0);
+ assert(lk1.mutex() == std::addressof(m0));
assert(lk1.owns_lock() == true);
assert(lk0.mutex() == nullptr);
assert(lk0.owns_lock() == false);
+ }
+ {
+ typedef nasty_mutex M;
+ M m0;
+ M m1;
+ std::shared_lock<M> lk0(m0);
+ std::shared_lock<M> lk1(m1);
+ lk1 = std::move(lk0);
+ assert(lk1.mutex() == std::addressof(m0));
+ assert(lk1.owns_lock() == true);
+ assert(lk0.mutex() == nullptr);
+ assert(lk0.owns_lock() == false);
+ }
}
diff --git a/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/move_ctor.pass.cpp b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/move_ctor.pass.cpp
index 4f4f6a5e9fbdb..c29a3fb04d0ff 100644
--- a/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/move_ctor.pass.cpp
+++ b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/move_ctor.pass.cpp
@@ -18,14 +18,28 @@
#include <shared_mutex>
#include <cassert>
+#include "nasty_containers.hpp"
int main()
{
- std::shared_timed_mutex m;
- std::shared_lock<std::shared_timed_mutex> lk0(m);
- std::shared_lock<std::shared_timed_mutex> lk = std::move(lk0);
- assert(lk.mutex() == &m);
+ {
+ typedef std::shared_timed_mutex M;
+ M m;
+ std::shared_lock<M> lk0(m);
+ std::shared_lock<M> lk = std::move(lk0);
+ assert(lk.mutex() == std::addressof(m));
assert(lk.owns_lock() == true);
assert(lk0.mutex() == nullptr);
assert(lk0.owns_lock() == false);
+ }
+ {
+ typedef nasty_mutex M;
+ M m;
+ std::shared_lock<M> lk0(m);
+ std::shared_lock<M> lk = std::move(lk0);
+ assert(lk.mutex() == std::addressof(m));
+ assert(lk.owns_lock() == true);
+ assert(lk0.mutex() == nullptr);
+ assert(lk0.owns_lock() == false);
+ }
}
diff --git a/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_adopt_lock.pass.cpp b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_adopt_lock.pass.cpp
index 995210221065e..341f0ce7efd2c 100644
--- a/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_adopt_lock.pass.cpp
+++ b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_adopt_lock.pass.cpp
@@ -18,12 +18,24 @@
#include <shared_mutex>
#include <cassert>
+#include "nasty_containers.hpp"
int main()
{
- std::shared_timed_mutex m;
- m.lock_shared();
- std::shared_lock<std::shared_timed_mutex> lk(m, std::adopt_lock);
- assert(lk.mutex() == &m);
+ {
+ typedef std::shared_timed_mutex M;
+ M m;
+ m.lock();
+ std::unique_lock<M> lk(m, std::adopt_lock);
+ assert(lk.mutex() == std::addressof(m));
assert(lk.owns_lock() == true);
+ }
+ {
+ typedef nasty_mutex M;
+ M m;
+ m.lock();
+ std::unique_lock<M> lk(m, std::adopt_lock);
+ assert(lk.mutex() == std::addressof(m));
+ assert(lk.owns_lock() == true);
+ }
}
diff --git a/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_defer_lock.pass.cpp b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_defer_lock.pass.cpp
index d81796b95bf3c..5fbb7244ef8ef 100644
--- a/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_defer_lock.pass.cpp
+++ b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_defer_lock.pass.cpp
@@ -18,11 +18,22 @@
#include <shared_mutex>
#include <cassert>
+#include "nasty_containers.hpp"
int main()
{
- std::shared_timed_mutex m;
- std::shared_lock<std::shared_timed_mutex> lk(m, std::defer_lock);
- assert(lk.mutex() == &m);
+ {
+ typedef std::shared_timed_mutex M;
+ M m;
+ std::unique_lock<M> lk(m, std::defer_lock);
+ assert(lk.mutex() == std::addressof(m));
assert(lk.owns_lock() == false);
+ }
+ {
+ typedef nasty_mutex M;
+ M m;
+ std::unique_lock<M> lk(m, std::defer_lock);
+ assert(lk.mutex() == std::addressof(m));
+ assert(lk.owns_lock() == false);
+ }
}
diff --git a/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/copy_assign.fail.cpp b/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/copy_assign.fail.cpp
index 4f477449d6a28..8d864ea8e7da6 100644
--- a/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/copy_assign.fail.cpp
+++ b/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/copy_assign.fail.cpp
@@ -16,16 +16,18 @@
#include <mutex>
#include <cassert>
-std::mutex m0;
-std::mutex m1;
-
int main()
{
- std::unique_lock<std::mutex> lk0(m0);
- std::unique_lock<std::mutex> lk1(m1);
+ {
+ typedef std::mutex M;
+ M m0;
+ M m1;
+ std::unique_lock<M> lk0(m0);
+ std::unique_lock<M> lk1(m1);
lk1 = lk0;
assert(lk1.mutex() == &m0);
assert(lk1.owns_lock() == true);
assert(lk0.mutex() == nullptr);
assert(lk0.owns_lock() == false);
+ }
}
diff --git a/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/copy_ctor.fail.cpp b/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/copy_ctor.fail.cpp
index 4888fe90d92c6..067302127cadf 100644
--- a/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/copy_ctor.fail.cpp
+++ b/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/copy_ctor.fail.cpp
@@ -16,14 +16,16 @@
#include <mutex>
#include <cassert>
-std::mutex m;
-
int main()
{
- std::unique_lock<std::mutex> lk0(m);
- std::unique_lock<std::mutex> lk = lk0;
+ {
+ typedef std::mutex M;
+ M m;
+ std::unique_lock<M> lk0(m);
+ std::unique_lock<M> lk = lk0;
assert(lk.mutex() == &m);
assert(lk.owns_lock() == true);
assert(lk0.mutex() == nullptr);
assert(lk0.owns_lock() == false);
+ }
}
diff --git a/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/move_assign.pass.cpp b/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/move_assign.pass.cpp
index 4dff853088ac7..e5db685e46e75 100644
--- a/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/move_assign.pass.cpp
+++ b/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/move_assign.pass.cpp
@@ -17,19 +17,34 @@
#include <mutex>
#include <cassert>
-
-std::mutex m0;
-std::mutex m1;
+#include "nasty_containers.hpp"
int main()
{
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
- std::unique_lock<std::mutex> lk0(m0);
- std::unique_lock<std::mutex> lk1(m1);
+ {
+ typedef std::mutex M;
+ M m0;
+ M m1;
+ std::unique_lock<M> lk0(m0);
+ std::unique_lock<M> lk1(m1);
+ lk1 = std::move(lk0);
+ assert(lk1.mutex() == std::addressof(m0));
+ assert(lk1.owns_lock() == true);
+ assert(lk0.mutex() == nullptr);
+ assert(lk0.owns_lock() == false);
+ }
+ {
+ typedef nasty_mutex M;
+ M m0;
+ M m1;
+ std::unique_lock<M> lk0(m0);
+ std::unique_lock<M> lk1(m1);
lk1 = std::move(lk0);
- assert(lk1.mutex() == &m0);
+ assert(lk1.mutex() == std::addressof(m0));
assert(lk1.owns_lock() == true);
assert(lk0.mutex() == nullptr);
assert(lk0.owns_lock() == false);
+ }
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
}
diff --git a/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/move_ctor.pass.cpp b/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/move_ctor.pass.cpp
index aa640ee6d746f..427deabc5a59d 100644
--- a/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/move_ctor.pass.cpp
+++ b/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/move_ctor.pass.cpp
@@ -17,17 +17,30 @@
#include <mutex>
#include <cassert>
-
-std::mutex m;
+#include "nasty_containers.hpp"
int main()
{
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
- std::unique_lock<std::mutex> lk0(m);
- std::unique_lock<std::mutex> lk = std::move(lk0);
- assert(lk.mutex() == &m);
+ {
+ typedef std::mutex M;
+ M m;
+ std::unique_lock<M> lk0(m);
+ std::unique_lock<M> lk = std::move(lk0);
+ assert(lk.mutex() == std::addressof(m));
+ assert(lk.owns_lock() == true);
+ assert(lk0.mutex() == nullptr);
+ assert(lk0.owns_lock() == false);
+ }
+ {
+ typedef nasty_mutex M;
+ M m;
+ std::unique_lock<M> lk0(m);
+ std::unique_lock<M> lk = std::move(lk0);
+ assert(lk.mutex() == std::addressof(m));
assert(lk.owns_lock() == true);
assert(lk0.mutex() == nullptr);
assert(lk0.owns_lock() == false);
+ }
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
}
diff --git a/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/mutex_adopt_lock.pass.cpp b/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/mutex_adopt_lock.pass.cpp
index 9c3a7b6505a46..20f7d249b6f49 100644
--- a/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/mutex_adopt_lock.pass.cpp
+++ b/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/mutex_adopt_lock.pass.cpp
@@ -17,12 +17,24 @@
#include <mutex>
#include <cassert>
+#include "nasty_containers.hpp"
int main()
{
- std::mutex m;
+ {
+ typedef std::mutex M;
+ M m;
m.lock();
- std::unique_lock<std::mutex> lk(m, std::adopt_lock);
- assert(lk.mutex() == &m);
+ std::unique_lock<M> lk(m, std::adopt_lock);
+ assert(lk.mutex() == std::addressof(m));
assert(lk.owns_lock() == true);
+ }
+ {
+ typedef nasty_mutex M;
+ M m;
+ m.lock();
+ std::unique_lock<M> lk(m, std::adopt_lock);
+ assert(lk.mutex() == std::addressof(m));
+ assert(lk.owns_lock() == true);
+ }
}
diff --git a/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/mutex_defer_lock.pass.cpp b/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/mutex_defer_lock.pass.cpp
index bf622311f0132..242dacb1eb922 100644
--- a/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/mutex_defer_lock.pass.cpp
+++ b/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/mutex_defer_lock.pass.cpp
@@ -17,11 +17,22 @@
#include <mutex>
#include <cassert>
+#include "nasty_containers.hpp"
int main()
{
- std::mutex m;
- std::unique_lock<std::mutex> lk(m, std::defer_lock);
- assert(lk.mutex() == &m);
+ {
+ typedef std::mutex M;
+ M m;
+ std::unique_lock<M> lk(m, std::defer_lock);
+ assert(lk.mutex() == std::addressof(m));
assert(lk.owns_lock() == false);
+ }
+ {
+ typedef nasty_mutex M;
+ M m;
+ std::unique_lock<M> lk(m, std::defer_lock);
+ assert(lk.mutex() == std::addressof(m));
+ assert(lk.owns_lock() == false);
+ }
}