[libcxx-commits] [libcxx] WIP [libc++][ranges] Applied [[nodiscard]] to `lazy_split` (PR #208036)
Hristo Hristov via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Jul 8 07:52:47 PDT 2026
================
@@ -0,0 +1,60 @@
+//===----------------------------------------------------------------------===//
+//
+// 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++20
+
+// Test the libc++ extension that std::ranges::lazy_split_view and std::views::lazy_split are marked as [[nodiscard]].
+
+#include <ranges>
+#include <string>
+#include <utility>
+
+void test() {
+ std::string str = "the quick brown fox";
+ char pattern = ' ';
+
+ auto v = std::views::lazy_split(str, pattern);
+
+ // [range.lazy.split.view]
+
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ v.base();
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::move(v).base();
+
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ v.begin();
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::as_const(v).begin();
+
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ v.end();
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::as_const(v).end();
+
+ // [range.lazy.split.outer-iterator]
----------------
Zingam wrote:
We test here: https://eel.is/c++draft/range.lazy.split.outer
Also lets have these sections:
https://eel.is/c++draft/range.lazy.split#inner
https://eel.is/c++draft/range.lazy.split#outer.value
```suggestion
// [range.lazy.split.outer]
...
// [range.lazy.split.outer.value]
...
// [range.lazy.split.inner]
...
```
https://github.com/llvm/llvm-project/pull/208036
More information about the libcxx-commits
mailing list