[libc-commits] [clang] [llvm] [mlir] [libc] [flang] [libcxx] [libc++][memory] P1132R8: out_ptr - a scalable output pointer abstraction (PR #73618)

Louis Dionne via libc-commits libc-commits at lists.llvm.org
Thu Dec 14 08:31:16 PST 2023


================
@@ -0,0 +1,97 @@
+// -*- 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___OUT_PTR_H
+#define _LIBCPP___OUT_PTR_H
+
+#include <__config>
+#include <__memory/addressof.h>
+#include <__memory/pointer_traits.h>
+#include <__memory/shared_ptr.h>
+#include <__memory/unique_ptr.h>
+#include <__type_traits/is_specialization.h>
+#include <__type_traits/is_void.h>
+#include <tuple>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+
+template <class _Tp>
+concept __resettable_adapted_ptr = requires(_Tp __ptr) { __ptr().reset(); };
+
+template <class _Smart, class _Pointer, class... _Args>
+class _LIBCPP_TEMPLATE_VIS out_ptr_t {
+  static_assert(!__is_specialization_v<_Smart, shared_ptr> || sizeof...(_Args) > 0,
+                "Specialization of std::shared_ptr<> requires a deleter.");
----------------
ldionne wrote:

I don't think we can have this `static_assert`, nor the one in `inout_ptr_t`. That would make us non-conforming, since something like

```
std::shared_ptr<int> int_ptr;
some_function(std::out_ptr<int*>(int_ptr));
```

is valid and would end up calling `int_ptr.reset(internal-ptr)`, and then eventually `delete internal-ptr` in `~shared_ptr`, which seems OK? If you agree, please add a test that this works as it should (right now it would fail to compile). The same applies to `inout_ptr_t`.

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


More information about the libc-commits mailing list