[libcxx-commits] [libcxx] 5613f77 - [libc++][ranges] Updated `ranges::to` `[[nodiscard]]` tests (#173574)

via libcxx-commits libcxx-commits at lists.llvm.org
Thu Apr 2 03:46:11 PDT 2026


Author: Hristo Hristov
Date: 2026-04-02T13:46:06+03:00
New Revision: 5613f7729311da94568e469412418450b695bc18

URL: https://github.com/llvm/llvm-project/commit/5613f7729311da94568e469412418450b695bc18
DIFF: https://github.com/llvm/llvm-project/commit/5613f7729311da94568e469412418450b695bc18.diff

LOG: [libc++][ranges] Updated `ranges::to` `[[nodiscard]]` tests (#173574)

- Updated and moved `ranges::to` `[[nodiscard]]` tests to the new
conventinional location.
- Removed libcxx/test/libcxx/diagnostics/ranges.nodiscard.verify.cpp,
which is now obsolete in favor of more specific test files.

# References:

- https://wg21.link/range.utility.conv
- https://wg21.link/range.utility.conv.to
- https://wg21.link/range.utility.conv.adaptors

Towards #172124

Added: 
    libcxx/test/libcxx/ranges/range.utility/range.utility.conv/nodiscard.verify.cpp

Modified: 
    

Removed: 
    libcxx/test/libcxx/diagnostics/ranges.nodiscard.verify.cpp


################################################################################
diff  --git a/libcxx/test/libcxx/diagnostics/ranges.nodiscard.verify.cpp b/libcxx/test/libcxx/diagnostics/ranges.nodiscard.verify.cpp
deleted file mode 100644
index ecdad4ae9ec64..0000000000000
--- a/libcxx/test/libcxx/diagnostics/ranges.nodiscard.verify.cpp
+++ /dev/null
@@ -1,57 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-// Check that ranges are marked [[nodiscard]] as a conforming extension
-
-// UNSUPPORTED: c++03, c++11, c++14, c++17
-
-// clang-format off
-
-#include <ranges>
-#include <functional>
-#include <vector>
-
-#include "test_macros.h"
-
-void test() {
-  std::vector<int> range;
-  std::ranges::less_equal pred;
-
-  std::views::drop(pred);                  // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
-
-  std::views::split(range, 3); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
-  std::views::split(1);        // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
-
-  std::views::take(range, 3); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
-  std::views::take(1);        // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
-
-#if TEST_STD_VER >= 23
-  std::views::drop(std::views::repeat(1)); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
-
-  std::views::repeat(1);                            // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
-  std::views::repeat(1, std::unreachable_sentinel); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
-
-  auto rvalue_view = std::views::as_rvalue(range);
-  std::views::as_rvalue(range);       // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
-  std::views::as_rvalue(rvalue_view); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
-
-  std::views::take(std::views::repeat(3), 3);                            // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
-  std::views::take(std::views::repeat(3, std::unreachable_sentinel), 3); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
-
-  std::allocator<int> alloc;
-
-  std::ranges::to<std::vector<int>>(range);         // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
-  std::ranges::to<std::vector<int>>(range, alloc);  // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
-  std::ranges::to<std::vector>(range);              // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
-  std::ranges::to<std::vector>(range, alloc);       // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
-  range | std::ranges::to<std::vector<int>>();      // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
-  range | std::ranges::to<std::vector<int>>(alloc); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
-  range | std::ranges::to<std::vector>();           // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
-  range | std::ranges::to<std::vector>(alloc);      // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
-#endif // TEST_STD_VER >= 23
-}

diff  --git a/libcxx/test/libcxx/ranges/range.utility/range.utility.conv/nodiscard.verify.cpp b/libcxx/test/libcxx/ranges/range.utility/range.utility.conv/nodiscard.verify.cpp
new file mode 100644
index 0000000000000..76579ef332544
--- /dev/null
+++ b/libcxx/test/libcxx/ranges/range.utility/range.utility.conv/nodiscard.verify.cpp
@@ -0,0 +1,54 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+
+// Check that functions are marked [[nodiscard]]
+
+#include <ranges>
+#include <vector>
+
+void test() {
+  std::vector<int> range;
+  std::allocator<int> alloc;
+
+  { // `ranges::to` base template -- the `_Container` type is a simple type template parameter.
+
+    // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+    std::ranges::to<std::vector<int>>(range);
+    // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+    std::ranges::to<std::vector<int>>(range, alloc);
+  }
+
+  { // `ranges::to` specialization -- `_Container` is a template template parameter requiring deduction to figure out the
+    // container element type.
+
+    // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+    std::ranges::to<std::vector>(range);
+    // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+    std::ranges::to<std::vector>(range, alloc);
+  }
+
+  { // Range adaptor closure object 1 -- wrapping the `ranges::to` version where `_Container` is a simple type template
+    // parameter.
+
+    // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+    std::ranges::to<std::vector<int>>();
+    // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+    std::ranges::to<std::vector<int>>(alloc);
+  }
+
+  { // Range adaptor closure object 2 -- wrapping the `ranges::to` version where `_Container` is a template template
+    // parameter.
+
+    // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+    std::ranges::to<std::vector>();
+    // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+    std::ranges::to<std::vector>(alloc);
+  }
+}


        


More information about the libcxx-commits mailing list