]>
Commit | Line | Data |
---|---|---|
1dd95239 VV |
1 | // Copyright (C) 2017 Free Software Foundation, Inc. |
2 | // | |
3 | // This file is part of the GNU ISO C++ Library. This library is free | |
4 | // software; you can redistribute it and/or modify it under the | |
5 | // terms of the GNU General Public License as published by the | |
6 | // Free Software Foundation; either version 3, or (at your option) | |
7 | // any later version. | |
8 | ||
9 | // This library is distributed in the hope that it will be useful, | |
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | // GNU General Public License for more details. | |
13 | ||
14 | // You should have received a copy of the GNU General Public License along | |
15 | // with this library; see the file COPYING3. If not see | |
16 | // <http://www.gnu.org/licenses/>. | |
17 | ||
af181c91 JW |
18 | // { dg-options "-std=gnu++17" } |
19 | // { dg-do compile { target c++1z } } | |
1dd95239 | 20 | |
af181c91 JW |
21 | #include <mutex> |
22 | ||
23 | template<typename T, typename U> struct require_same; | |
24 | template<typename T> struct require_same<T, T> { using type = void; }; | |
1dd95239 | 25 | |
af181c91 JW |
26 | template<typename T, typename U> |
27 | typename require_same<T, U>::type | |
28 | check_type(U&) { } | |
29 | ||
30 | void | |
31 | test01() | |
1dd95239 | 32 | { |
af181c91 JW |
33 | std::scoped_lock l0; |
34 | check_type<std::scoped_lock<>>(l0); | |
35 | ||
36 | struct BasicLockable { | |
37 | void lock() { } | |
38 | void unlock() { } | |
39 | } m1; | |
40 | ||
41 | std::scoped_lock l1(m1); | |
42 | check_type<std::scoped_lock<BasicLockable>>(l1); | |
43 | ||
44 | struct Lockable { | |
45 | void lock() { } | |
46 | void unlock() { } | |
47 | bool try_lock() { return true; } | |
48 | } m2; | |
49 | ||
50 | std::mutex m3; | |
51 | std::scoped_lock l2(m2, m3); | |
52 | check_type<std::scoped_lock<Lockable, std::mutex>>(l2); | |
1dd95239 | 53 | } |
e12d3780 JW |
54 | |
55 | void | |
56 | test02() | |
57 | { | |
58 | std::scoped_lock l0(std::adopt_lock); | |
59 | check_type<std::scoped_lock<>>(l0); | |
60 | ||
61 | struct BasicLockable { | |
62 | void lock() { } | |
63 | void unlock() { } | |
64 | } m1; | |
65 | ||
66 | std::scoped_lock l1(std::adopt_lock, m1); | |
67 | check_type<std::scoped_lock<BasicLockable>>(l1); | |
68 | ||
69 | struct Lockable { | |
70 | void lock() { } | |
71 | void unlock() { } | |
72 | bool try_lock() { return true; } | |
73 | } m2; | |
74 | ||
75 | std::mutex m3; | |
76 | std::scoped_lock l2(std::adopt_lock, m2, m3); | |
77 | check_type<std::scoped_lock<Lockable, std::mutex>>(l2); | |
78 | } |