[libcxx-commits] [libcxx] [libc++] P2590R2: Explicit lifetime management (PR #107206)

via libcxx-commits libcxx-commits at lists.llvm.org
Wed Sep 4 03:05:15 PDT 2024


================
@@ -0,0 +1,47 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___MEMORY_START_LIFETIME_AS_ARRAY_H
+#define _LIBCPP___MEMORY_START_LIFETIME_AS_ARRAY_H
+
+#include <__config>
+#include <__memory/start_lifetime_as.h>
+#include <cstddef>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <class _Tp>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Tp* start_lifetime_as_array(void* __p, [[maybe_unused]] size_t __n) _NOEXCEPT {
+  return static_cast<_Tp*>(__p);
----------------
phyBrackets wrote:

The function itself doesn't actually do anything at runtime.  It's a no-op in terms of generated code. It happens at the compiler level. When the compiler sees a call to this function, it treats it as a signal that it should consider the lifetime of an array of  `_Tp` objects to have begun at the memory location pointed to by `__p` , even though no constructors have been called. Or is it intended something else? I am not sure, Could you explain?

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


More information about the libcxx-commits mailing list