[libcxx-commits] [libcxx] c77af00 - [libc++] mark barrier constructor as explicit in <barrier>

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Wed Jul 12 12:31:21 PDT 2023


Author: Edoardo Sanguineti
Date: 2023-07-12T12:31:16-07:00
New Revision: c77af00eb98c8029b29b5b86396b109fd343c11b

URL: https://github.com/llvm/llvm-project/commit/c77af00eb98c8029b29b5b86396b109fd343c11b
DIFF: https://github.com/llvm/llvm-project/commit/c77af00eb98c8029b29b5b86396b109fd343c11b.diff

LOG: [libc++] mark barrier constructor as explicit in <barrier>

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

Added: 
    libcxx/test/std/thread/thread.barrier/ctor.compile.pass.cpp

Modified: 
    libcxx/include/barrier

Removed: 
    


################################################################################
diff  --git a/libcxx/include/barrier b/libcxx/include/barrier
index 2ef232d46247f2..64e48775ea0930 100644
--- a/libcxx/include/barrier
+++ b/libcxx/include/barrier
@@ -298,7 +298,7 @@ public:
     }
 
     _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
-    barrier(ptr
diff _t __count, _CompletionF __completion = _CompletionF())
+    explicit barrier(ptr
diff _t __count, _CompletionF __completion = _CompletionF())
         : __b_(__count, _VSTD::move(__completion)) {
     }
 

diff  --git a/libcxx/test/std/thread/thread.barrier/ctor.compile.pass.cpp b/libcxx/test/std/thread/thread.barrier/ctor.compile.pass.cpp
new file mode 100644
index 00000000000000..d47127a18613b7
--- /dev/null
+++ b/libcxx/test/std/thread/thread.barrier/ctor.compile.pass.cpp
@@ -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(ptr
diff _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::ptr
diff _t>(), "This constructor must be explicit");


        


More information about the libcxx-commits mailing list