[libcxx] [llvm] [libc++] Implement P2442R1 `std::views::chunk` (PR #171234)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 9 00:53:42 PST 2025
================
@@ -0,0 +1,26 @@
+//===----------------------------------------------------------------------===//
+//
+// 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++23
+
+// <ranges>
+
+// Test the libc++ extension that std::ranges::chunk_view::iterator<Const>::operator* is marked as [[nodiscard]].
+
+#include <ranges>
+#include <utility>
+
+void test() {
+ char range[6] = {'x', 'x', 'y', 'y', 'z', 'z'};
+ auto view = range | std::views::chunk(2);
+
+ // clang-format off
+ *view.begin(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
+ *std::as_const(view).begin(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
+ // clang-format on
+}
----------------
anonymouspc wrote:
Ok. I've collected all the `[[nodiscard]]` tests into `libcxx/test/libcxx/ranges/range.adaptors/range.chunk/nodiscard.verify.cpp` , along with a `no_unique_address.compile.pass.cpp`.
https://github.com/llvm/llvm-project/pull/171234
More information about the llvm-commits
mailing list