public:
_LIBCPP_INLINE_VISIBILITY
- __atomic_semaphore_base(ptrdiff_t __count) : __a(__count)
+ constexpr explicit __atomic_semaphore_base(ptrdiff_t __count) : __a(__count)
{
}
_LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
public:
_LIBCPP_INLINE_VISIBILITY
- __platform_semaphore_base(ptrdiff_t __count) :
+ explicit __platform_semaphore_base(ptrdiff_t __count) :
__semaphore()
{
__libcpp_semaphore_init(&__semaphore, __count);
}
_LIBCPP_INLINE_VISIBILITY
- counting_semaphore(ptrdiff_t __count = 0) : __semaphore(__count) { }
+ constexpr explicit counting_semaphore(ptrdiff_t __count) : __semaphore(__count) { }
~counting_semaphore() = default;
counting_semaphore(const counting_semaphore&) = delete;
#include <semaphore>
#include <chrono>
#include <thread>
+#include <type_traits>
#include "make_test_thread.h"
#include "test_macros.h"
+static_assert(std::is_same<std::binary_semaphore, std::counting_semaphore<1>>::value, "");
+
int main(int, char**)
{
std::binary_semaphore s(1);
--- /dev/null
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// UNSUPPORTED: libcpp-has-no-threads
+// UNSUPPORTED: c++03, c++11
+
+// <semaphore>
+
+// constexpr explicit counting_semaphore(ptrdiff_t desired);
+
+#include <semaphore>
+#include <type_traits>
+
+#include "test_macros.h"
+
+static_assert(!std::is_default_constructible<std::binary_semaphore>::value, "");
+static_assert(!std::is_default_constructible<std::counting_semaphore<>>::value, "");
+
+static_assert(!std::is_convertible<int, std::binary_semaphore>::value, "");
+static_assert(!std::is_convertible<int, std::counting_semaphore<>>::value, "");
+
+#if 0 // TODO FIXME: the ctor should be constexpr when TEST_STD_VER > 17
+constinit std::binary_semaphore bs(1);
+constinit std::counting_semaphore cs(1);
+#endif
int main(int, char**)
{
- static_assert(std::counting_semaphore<>::max() > 0, "");
+ static_assert(std::counting_semaphore<>::max() >= 1, "");
static_assert(std::counting_semaphore<1>::max() >= 1, "");
- static_assert(std::counting_semaphore<std::numeric_limits<int>::max()>::max() >= 1, "");
- static_assert(std::counting_semaphore<std::numeric_limits<ptrdiff_t>::max()>::max() >= 1, "");
- static_assert(std::counting_semaphore<1>::max() == std::binary_semaphore::max(), "");
+ static_assert(std::counting_semaphore<std::numeric_limits<int>::max()>::max() >= std::numeric_limits<int>::max(), "");
+ static_assert(std::counting_semaphore<std::numeric_limits<ptrdiff_t>::max()>::max() == std::numeric_limits<ptrdiff_t>::max(), "");
return 0;
}