[libcxx-commits] [PATCH] D154957: [libc++] add test for latch ctor

Edo via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Jul 11 06:05:44 PDT 2023


diamante0018 created this revision.
Herald added a subscriber: kristof.beyls.
Herald added a project: All.
diamante0018 requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.

Currently, there are no tests to confirm without a doubt the constructor of latch is really constexpr and explicit.
I think this would be an addition that it would not harm to have. In another revision, I was asked to add tests for an almost identical case which made me consider adding this test for the latch class too.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154957

Files:
  libcxx/test/std/thread/thread.latch/ctor.pass.cpp


Index: libcxx/test/std/thread/thread.latch/ctor.pass.cpp
===================================================================
--- /dev/null
+++ libcxx/test/std/thread/thread.latch/ctor.pass.cpp
@@ -0,0 +1,36 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+
+// XFAIL: availability-synchronization_library-missing
+
+// <latch>
+
+// inline constexpr explicit latch(ptrdiff_t __expected);
+
+// Make sure that the ctor of latch is constexpr and explicit.
+
+#include <latch>
+
+#include "test_convertible.h"
+
+static_assert(!test_convertible<std::latch>(), "This constructor must be explicit");
+
+constexpr bool test() {
+  [[maybe_unused]] std::latch l{5};
+  return true;
+}
+
+int main(int, char**) {
+  test();
+  static_assert(test());
+
+  return 0;
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154957.539051.patch
Type: text/x-patch
Size: 1153 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20230711/3b2af969/attachment.bin>


More information about the libcxx-commits mailing list