File tree Expand file tree Collapse file tree 4 files changed +39
-7
lines changed
test/std/thread/thread.semaphore Expand file tree Collapse file tree 4 files changed +39
-7
lines changed Original file line number Diff line number Diff line change @@ -82,7 +82,7 @@ class __atomic_semaphore_base
82
82
83
83
public:
84
84
_LIBCPP_INLINE_VISIBILITY
85
- __atomic_semaphore_base (ptrdiff_t __count) : __a(__count)
85
+ constexpr explicit __atomic_semaphore_base (ptrdiff_t __count) : __a(__count)
86
86
{
87
87
}
88
88
_LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
@@ -136,7 +136,7 @@ class __platform_semaphore_base
136
136
137
137
public:
138
138
_LIBCPP_INLINE_VISIBILITY
139
- __platform_semaphore_base (ptrdiff_t __count) :
139
+ explicit __platform_semaphore_base (ptrdiff_t __count) :
140
140
__semaphore()
141
141
{
142
142
__libcpp_semaphore_init (&__semaphore, __count);
@@ -190,7 +190,7 @@ public:
190
190
}
191
191
192
192
_LIBCPP_INLINE_VISIBILITY
193
- counting_semaphore (ptrdiff_t __count = 0 ) : __semaphore(__count) { }
193
+ constexpr explicit counting_semaphore (ptrdiff_t __count) : __semaphore(__count) { }
194
194
~counting_semaphore () = default ;
195
195
196
196
counting_semaphore (const counting_semaphore&) = delete ;
Original file line number Diff line number Diff line change 18
18
#include < semaphore>
19
19
#include < chrono>
20
20
#include < thread>
21
+ #include < type_traits>
21
22
22
23
#include " make_test_thread.h"
23
24
#include " test_macros.h"
24
25
26
+ static_assert (std::is_same<std::binary_semaphore, std::counting_semaphore<1 >>::value, " " );
27
+
25
28
int main (int , char **)
26
29
{
27
30
std::binary_semaphore s (1 );
Original file line number Diff line number Diff line change
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++03, c++11
11
+
12
+ // <semaphore>
13
+
14
+ // constexpr explicit counting_semaphore(ptrdiff_t desired);
15
+
16
+ #include < semaphore>
17
+ #include < type_traits>
18
+
19
+ #include " test_macros.h"
20
+
21
+ static_assert (!std::is_default_constructible<std::binary_semaphore>::value, " " );
22
+ static_assert (!std::is_default_constructible<std::counting_semaphore<>>::value, " " );
23
+
24
+ static_assert (!std::is_convertible<int , std::binary_semaphore>::value, " " );
25
+ static_assert (!std::is_convertible<int , std::counting_semaphore<>>::value, " " );
26
+
27
+ #if 0 // TODO FIXME: the ctor should be constexpr when TEST_STD_VER > 17
28
+ constinit std::binary_semaphore bs(1);
29
+ constinit std::counting_semaphore cs(1);
30
+ #endif
Original file line number Diff line number Diff line change 18
18
19
19
int main (int , char **)
20
20
{
21
- static_assert (std::counting_semaphore<>::max () > 0 , " " );
21
+ static_assert (std::counting_semaphore<>::max () >= 1 , " " );
22
22
static_assert (std::counting_semaphore<1 >::max () >= 1 , " " );
23
- static_assert (std::counting_semaphore<std::numeric_limits<int >::max ()>::max () >= 1 , " " );
24
- static_assert (std::counting_semaphore<std::numeric_limits<ptrdiff_t >::max ()>::max () >= 1 , " " );
25
- static_assert (std::counting_semaphore<1 >::max () == std::binary_semaphore::max (), " " );
23
+ static_assert (std::counting_semaphore<std::numeric_limits<int >::max ()>::max () >= std::numeric_limits<int >::max (), " " );
24
+ static_assert (std::counting_semaphore<std::numeric_limits<ptrdiff_t >::max ()>::max () == std::numeric_limits<ptrdiff_t >::max (), " " );
26
25
return 0 ;
27
26
}
You can’t perform that action at this time.
0 commit comments