Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions stl/inc/barrier
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ public:

using arrival_token = _Arrival_token<_Completion_function>;

constexpr explicit barrier(
const ptrdiff_t _Expected, _Completion_function _Fn = _Completion_function()) noexcept /* strengthened */
constexpr explicit barrier(const ptrdiff_t _Expected, _Completion_function _Fn = _Completion_function())
noexcept(is_nothrow_move_constructible_v<_Completion_function>) // strengthened
: _Val(_One_then_variadic_args_t{}, _STD move(_Fn), _Expected << _Barrier_value_shift) {
_STL_VERIFY(_Expected >= 0 && _Expected <= (max) (),
"Precondition: expected >= 0 and expected <= max() (N4950 [thread.barrier.class]/9)");
Expand Down
19 changes: 19 additions & 0 deletions tests/std/tests/P1135R6_barrier/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
#include <atomic>
#include <barrier>
#include <cassert>
#include <cstddef>
#include <exception>
#include <thread>
#include <type_traits>
#include <utility>

void test() {
Expand Down Expand Up @@ -125,12 +128,28 @@ void test_functor_types() {
};
std::barrier b1{1, f1{0, 0, 0}};
b1.arrive_and_wait();
static_assert(std::is_nothrow_constructible_v<std::barrier<f1>, std::ptrdiff_t, f1>); // strengthened

std::barrier b2{1, barrier_callback_function};
b2.arrive_and_wait();

std::barrier b3{1, []() noexcept {}};
b3.arrive_and_wait();

struct f2 {
void operator()() noexcept {}

f2() = default;
f2(f2&&) {
throw std::exception{};
}
};
try {
std::barrier b4{1, f2{}};
assert(false);
static_assert(!std::is_nothrow_constructible_v<std::barrier<f2>, std::ptrdiff_t, f2>);
} catch (const std::exception&) {
}
}

int main() {
Expand Down