xref: /llvm-project/libcxx/test/libcxx/thread/thread.barrier/assert.ctor.pass.cpp (revision 58780b811c23df3d928d8452ee21c862dde754a2)
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 // UNSUPPORTED: no-threads
9 // UNSUPPORTED: c++03, c++11, c++14, c++17
10 // REQUIRES: libcpp-hardening-mode={{extensive|debug}}
11 
12 // XFAIL: libcpp-hardening-mode=debug && availability-verbose_abort-missing
13 
14 // REQUIRES: has-unix-headers
15 
16 // <barrier>
17 
18 // class barrier;
19 
20 // barrier(ptrdiff_t __count, _CompletionF __completion = _CompletionF());
21 
22 // Make sure that constructing barrier with a negative value triggers an assertion
23 
24 #include <barrier>
25 
26 #include "check_assertion.h"
27 
main(int,char **)28 int main(int, char**) {
29   {
30     TEST_LIBCPP_ASSERT_FAILURE(
31         [] { std::barrier<> b(-1); }(),
32         "barrier::barrier(ptrdiff_t, CompletionFunction): barrier cannot be initialized with a negative value");
33   }
34 
35   {
36     TEST_LIBCPP_ASSERT_FAILURE(
37         [] {
38           auto completion = []() {};
39           std::barrier<decltype(completion)> b(-1, completion);
40         }(),
41         "barrier::barrier(ptrdiff_t, CompletionFunction): barrier cannot be initialized with a negative value");
42   }
43 
44   // We can't check the precondition for max() because there's no value
45   // that would violate the precondition (in our implementation)
46 
47   return 0;
48 }
49