[libcxx-commits] [libcxx] [libc++] Implement the `indirect` half of P3019R14: Vocabulary Types for Composite Class Design (PR #166717)

Hristo Hristov via libcxx-commits libcxx-commits at lists.llvm.org
Sun Dec 7 20:53:53 PST 2025


================
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: std-at-least-c++26
+
+// <memory>
+
+// Test the libc++ extension that std::indirect's observers are marked as [[nodiscard]].
+
+#include <memory>
+#include <utility>
+
+void test(std::indirect<int>& i) {
+  // clang-format off
+  *i; // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
+  *std::move(i); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
+  *std::as_const(i); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
+  *std::move(std::as_const(i)); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
+  i.valueless_after_move(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
+  i.get_allocator(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
+  i.operator->(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
+  std::as_const(i).operator->(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
+  // clang-format on
----------------
H-G-Hristov wrote:

You don't have tests for the comparison operators and hash, but then you shouldn't annotate the comparison operators as the compiler should provide a diagnostic, which is our current agreement.

Can you also rename this file to just `nodiscard.verify.cpp` and move it one directory up: `libcxx/test/libcxx/memory/indirect/nodiscard.verify.cpp`

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


More information about the libcxx-commits mailing list