[libcxx-commits] [libcxx] [libcxx] implement LWG4148: unique_ptr::operator* should not allow dangling references (PR #128213)
Mark de Wever via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Feb 21 11:08:06 PST 2025
================
@@ -0,0 +1,28 @@
+//===----------------------------------------------------------------------===//
+//
+// 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>
+
+#include <iostream>
+#include <memory>
+
+using namespace std;
+
+struct deleter {
+ using pointer = long*;
+ void operator()(pointer) const {}
+};
+
+int main(int argc, char const *argv[]) {
+ long l = 0;
+ std::unique_ptr<const int, deleter> p(&l);
+ // Error: indirection requires pointer operand ('std::unique_ptr<const int, deleter>' invalid)
+ int i = *p;
+ cout << i << endl;
----------------
mordante wrote:
This is fine for debugging, but in the final test this should be removed, including the `iostream` include.
https://github.com/llvm/llvm-project/pull/128213
More information about the libcxx-commits
mailing list