Skip to content

Commit

Permalink
[libc++] mark barrier constructor as explicit in <barrier>
Browse files Browse the repository at this point in the history
If I read the standard correctly, the public constructor of "barrier" should be marked as "constexpr explicit".
I see some of the internal classes used by the barrier header are correctly marked but I think, if I'm not mistaken, the standard would like the public class to have the correct definition as well.

Because the implementation that llvm uses by default is not constexpr friendly at this time, this revision will focus on only marking it as explicit.

Reviewed By: #libc, philnik, Mordante

Spies: philnik, Mordante, libcxx-commits

Differential Revision: https://reviews.llvm.org/D154590
  • Loading branch information
diamante0018 authored and philnik777 committed Jul 12, 2023
1 parent 6071273 commit c77af00
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion libcxx/include/barrier
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ public:
}

_LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
barrier(ptrdiff_t __count, _CompletionF __completion = _CompletionF())
explicit barrier(ptrdiff_t __count, _CompletionF __completion = _CompletionF())
: __b_(__count, _VSTD::move(__completion)) {
}

Expand Down
22 changes: 22 additions & 0 deletions libcxx/test/std/thread/thread.barrier/ctor.compile.pass.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//===----------------------------------------------------------------------===//
//
// 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: no-threads
// UNSUPPORTED: c++03, c++11

// <barrier>

// explicit barrier(ptrdiff_t __count, _CompletionF __completion = _CompletionF());

// Make sure that the ctor of barrier is explicit.

#include <barrier>

#include "test_convertible.h"

static_assert(!test_convertible<std::barrier<>, std::ptrdiff_t>(), "This constructor must be explicit");

0 comments on commit c77af00

Please sign in to comment.