[libcxx-commits] [clang] [libcxx] [Clang][libc++] Implement C++23 std::start_lifetime_as (P2590R2, P2679R2) (PR #196286)

A. Jiang via libcxx-commits libcxx-commits at lists.llvm.org
Thu May 7 05:20:50 PDT 2026


================
@@ -0,0 +1,35 @@
+//===----------------------------------------------------------------------===//
+// 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: c++03, c++11, c++14, c++17, c++20
+
+#include <memory>
+
+struct NonTrivial {
+  int x;
+  ~NonTrivial() {}
+};
+
+struct Incomplete; // expected-note {{forward declaration of 'Incomplete'}}
+
+void test_invalid_types(void* p) {
+  // expected-error@*:* {{type 'NonTrivial' is not an implicit-lifetime type, cannot start lifetime}}
+  std::start_lifetime_as<NonTrivial>(p);
+
+  // expected-error@*:* {{incomplete type 'Incomplete' where a complete type is required}}
+  std::start_lifetime_as<Incomplete>(p);
+
+  // expected-error@*:* {{type 'void' is not an implicit-lifetime type, cannot start lifetime}}
+  std::start_lifetime_as<void>(p);
+
+  // expected-error@*:* {{static_cast from 'void *' to 'void (*)()' is not allowed}}
+  std::start_lifetime_as<void()>(p);
+}
+
+void test_constexpr() {
----------------
frederick-vs-ja wrote:

This looks quite novel. We almost never test missing of `constexpr`.

https://github.com/llvm/llvm-project/pull/196286


More information about the libcxx-commits mailing list