[libcxx-commits] [libcxx] [libc++][unique_ptr] Implement LWG 4144: Disallow unique_ptr<T&, D> (PR #209018)

via libcxx-commits libcxx-commits at lists.llvm.org
Sun Jul 12 21:28:04 PDT 2026


================
@@ -0,0 +1,40 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// <memory>
+
+// unique_ptr
+
+// A program that instantiates the definition of unique_ptr<T, D> is ill-formed if T* is an invalid type.
+
+// LWG 4144
+
+// XFAIL: FROZEN-CXX03-HEADERS-FIXME
+
+#include <memory>
+
+struct Deleter {
+  typedef int* pointer;
+
+  void operator()(pointer) const;
+};
+
+typedef void Function();
+typedef void AbominableFunction() const;
+
+void pointable_function_type() { (void)sizeof(std::unique_ptr<Function, Deleter>); }
+
+void reference_type() {
+  // expected-error-re@*:* {{static assertion failed {{.*}}unique_ptr<T, D> requires T* to be a valid type}}
+  (void)sizeof(std::unique_ptr<int&, Deleter>);
+}
+
+void abominable_function_type() {
+  // expected-error-re@*:* {{static assertion failed {{.*}}unique_ptr<T, D> requires T* to be a valid type}}
+  (void)sizeof(std::unique_ptr<AbominableFunction, Deleter>);
+}
----------------
emmett2020 wrote:

Thanks for the review. I think I'll try to merge test cases into one first when reasonable.

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


More information about the libcxx-commits mailing list