diff --git a/libcxx/include/semaphore b/libcxx/include/semaphore --- a/libcxx/include/semaphore +++ b/libcxx/include/semaphore @@ -82,7 +82,7 @@ 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 @@ -136,7 +136,7 @@ public: _LIBCPP_INLINE_VISIBILITY - __platform_semaphore_base(ptrdiff_t __count) : + explicit __platform_semaphore_base(ptrdiff_t __count) : __semaphore() { __libcpp_semaphore_init(&__semaphore, __count); @@ -190,7 +190,7 @@ } _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; diff --git a/libcxx/test/std/thread/thread.semaphore/binary.pass.cpp b/libcxx/test/std/thread/thread.semaphore/binary.pass.cpp --- a/libcxx/test/std/thread/thread.semaphore/binary.pass.cpp +++ b/libcxx/test/std/thread/thread.semaphore/binary.pass.cpp @@ -18,10 +18,13 @@ #include #include #include +#include #include "make_test_thread.h" #include "test_macros.h" +static_assert(std::is_same>::value, ""); + int main(int, char**) { std::binary_semaphore s(1); diff --git a/libcxx/test/std/thread/thread.semaphore/ctor.compile.pass.cpp b/libcxx/test/std/thread/thread.semaphore/ctor.compile.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/thread/thread.semaphore/ctor.compile.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// 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 + +// + +// constexpr explicit counting_semaphore(ptrdiff_t desired); + +#include +#include + +#include "test_macros.h" + +static_assert(!std::is_default_constructible::value, ""); +static_assert(!std::is_default_constructible>::value, ""); + +static_assert(!std::is_convertible::value, ""); +static_assert(!std::is_convertible>::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 diff --git a/libcxx/test/std/thread/thread.semaphore/max.pass.cpp b/libcxx/test/std/thread/thread.semaphore/max.pass.cpp --- a/libcxx/test/std/thread/thread.semaphore/max.pass.cpp +++ b/libcxx/test/std/thread/thread.semaphore/max.pass.cpp @@ -18,10 +18,9 @@ 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::max()>::max() >= 1, ""); - static_assert(std::counting_semaphore::max()>::max() >= 1, ""); - static_assert(std::counting_semaphore<1>::max() == std::binary_semaphore::max(), ""); + static_assert(std::counting_semaphore::max()>::max() >= std::numeric_limits::max(), ""); + static_assert(std::counting_semaphore::max()>::max() == std::numeric_limits::max(), ""); return 0; }