[libcxx-commits] [libcxx] [libc++] Implement P2442R1 `std::views::chunk` (PR #171234)
Hristo Hristov via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Jun 25 23:04:39 PDT 2026
================
@@ -0,0 +1,73 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 that functions are marked [[nodiscard]].
+
+#include <ranges>
+#include <utility>
+
+void test() {
+ char range[6] = {'x', 'x', 'y', 'y', 'z', 'z'};
+ auto view = range | std::views::chunk(2);
+
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ view.base();
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::as_const(view).base();
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::move(std::as_const(view)).base();
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::move(view).base();
+
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ view.begin();
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::as_const(view).begin();
+
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::ranges::iter_move(view.begin());
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::ranges::iter_move(std::as_const(view).begin());
+
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ view.end();
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::as_const(view).end();
+
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::ranges::iter_move(view.end());
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::ranges::iter_move(std::as_const(view).end());
+
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ *view.begin();
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ *std::as_const(view).begin();
+
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ (view.begin() == view.end());
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ (std::as_const(view).begin() == view.end());
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ (view.begin() == std::as_const(view).end());
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ (std::as_const(view).begin() == std::as_const(view).end());
----------------
Zingam wrote:
```suggestion
```
Please remove. In fact you have added many more `[[nodiscard]]`s that are untested but they need to be reverted as per: https://libcxx.llvm.org/CodingGuidelines.html#apply-nodiscard-where-relevant
https://github.com/llvm/llvm-project/pull/171234
More information about the libcxx-commits
mailing list