diff --git a/stl/inc/barrier b/stl/inc/barrier index 2f6fbeab428..230fc3640ad 100644 --- a/stl/inc/barrier +++ b/stl/inc/barrier @@ -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)"); diff --git a/tests/std/tests/P1135R6_barrier/test.cpp b/tests/std/tests/P1135R6_barrier/test.cpp index 0b04f8e5266..0e59e3c7430 100644 --- a/tests/std/tests/P1135R6_barrier/test.cpp +++ b/tests/std/tests/P1135R6_barrier/test.cpp @@ -4,7 +4,10 @@ #include #include #include +#include +#include #include +#include #include void test() { @@ -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::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::ptrdiff_t, f2>); + } catch (const std::exception&) { + } } int main() {