[libcxx-commits] [libcxx] [libcxx] adds ranges::fold_left_with_iter and ranges::fold_left (PR #75259)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Fri Dec 15 14:26:31 PST 2023


================
@@ -87,4 +89,15 @@ void test() {
   std::ranges::unique(iter, iter); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
   std::ranges::upper_bound(range, 1); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
   std::ranges::upper_bound(iter, iter, 1); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
+
+#if TEST_STD_VER >= 23
+  std::ranges::fold_left(range, 0, std::plus());
+  // expected-warning at -1{{ignoring return value of function declared with 'nodiscard' attribute}}
----------------
philnik777 wrote:

If you agree that it's not good code, I don't really see the problem with warning here. There's lots of correct code that the compiler generates warnings on. You wouldn't want to remove `[[nodiscard]]` from `std::count` just because there are valid ways to use the function without inspecting the return value, would you?

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


More information about the libcxx-commits mailing list