[libc-commits] [lldb] [llvm] [libcxx] [flang] [libc] [libcxxabi] [clang-tools-extra] [clang] [compiler-rt] Move nondiscard tests of ranges::contains() to the right place. (PR #76887)

via libc-commits libc-commits at lists.llvm.org
Thu Jan 4 11:34:48 PST 2024


https://github.com/ZijunZhaoCCK updated https://github.com/llvm/llvm-project/pull/76887

>From 9b90c41bd209a49de85987529bd7286401b01ef2 Mon Sep 17 00:00:00 2001
From: Zijun Zhao <zijunzhao at google.com>
Date: Wed, 3 Jan 2024 18:27:09 -0800
Subject: [PATCH 1/2] Move nondiscard tests of ranges::contains() to the right
 place.

---
 .../libcxx/diagnostics/nodiscard_extensions.compile.pass.cpp | 3 ---
 .../test/libcxx/diagnostics/nodiscard_extensions.verify.cpp  | 5 -----
 .../diagnostics/ranges.nodiscard_extensions.compile.pass.cpp | 2 ++
 .../diagnostics/ranges.nodiscard_extensions.verify.cpp       | 4 ++++
 4 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/libcxx/test/libcxx/diagnostics/nodiscard_extensions.compile.pass.cpp b/libcxx/test/libcxx/diagnostics/nodiscard_extensions.compile.pass.cpp
index 641fcd9233bc2e..e9fab0c75a98e9 100644
--- a/libcxx/test/libcxx/diagnostics/nodiscard_extensions.compile.pass.cpp
+++ b/libcxx/test/libcxx/diagnostics/nodiscard_extensions.compile.pass.cpp
@@ -45,9 +45,6 @@ void test_algorithms() {
 #if TEST_STD_VER >= 17
   std::clamp(2, 1, 3);
   std::clamp(2, 3, 1, std::greater<int>());
-#endif
-#if TEST_STD_VER >= 23
-  std::ranges::contains(arr, arr + 1, 1);
 #endif
   std::count_if(std::begin(arr), std::end(arr), P());
   std::count(std::begin(arr), std::end(arr), 1);
diff --git a/libcxx/test/libcxx/diagnostics/nodiscard_extensions.verify.cpp b/libcxx/test/libcxx/diagnostics/nodiscard_extensions.verify.cpp
index 1e3f537f01ed6e..d7a26d99e52233 100644
--- a/libcxx/test/libcxx/diagnostics/nodiscard_extensions.verify.cpp
+++ b/libcxx/test/libcxx/diagnostics/nodiscard_extensions.verify.cpp
@@ -60,11 +60,6 @@ void test_algorithms() {
   std::clamp(2, 1, 3, std::greater<int>());
 #endif
 
-#if TEST_STD_VER >= 23
-  // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
-  std::ranges::contains(arr, arr + 1, 1);
-#endif
-
   // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
   std::count_if(std::begin(arr), std::end(arr), P());
 
diff --git a/libcxx/test/libcxx/diagnostics/ranges.nodiscard_extensions.compile.pass.cpp b/libcxx/test/libcxx/diagnostics/ranges.nodiscard_extensions.compile.pass.cpp
index 7e2d64b8c9b618..9dc9c46ad89090 100644
--- a/libcxx/test/libcxx/diagnostics/ranges.nodiscard_extensions.compile.pass.cpp
+++ b/libcxx/test/libcxx/diagnostics/ranges.nodiscard_extensions.compile.pass.cpp
@@ -28,6 +28,8 @@ void test() {
   std::ranges::binary_search(range, 1);
   std::ranges::binary_search(iter, iter, 1);
   std::ranges::clamp(1, 2, 3);
+  std::ranges::contains(range, 1);
+  std::ranges::contains(iter, iter, 1);
   std::ranges::count_if(range, pred);
   std::ranges::count_if(iter, iter, pred);
   std::ranges::count(range, 1);
diff --git a/libcxx/test/libcxx/diagnostics/ranges.nodiscard_extensions.verify.cpp b/libcxx/test/libcxx/diagnostics/ranges.nodiscard_extensions.verify.cpp
index f0a0e4889a7603..5e45ad086cbd08 100644
--- a/libcxx/test/libcxx/diagnostics/ranges.nodiscard_extensions.verify.cpp
+++ b/libcxx/test/libcxx/diagnostics/ranges.nodiscard_extensions.verify.cpp
@@ -91,6 +91,10 @@ void test() {
   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::contains(range, 1);
+  // expected-warning at -1{{ignoring return value of function declared with 'nodiscard' attribute}}
+  std::ranges::contains(iter, iter, 1);
+  // expected-warning at -1{{ignoring return value of function declared with 'nodiscard' attribute}}
   std::ranges::fold_left(range, 0, std::plus());
   // expected-warning at -1{{ignoring return value of function declared with 'nodiscard' attribute}}
   std::ranges::fold_left(iter, iter, 0, std::plus());

>From 8df3a07eb4d9a13d6300ce7e5ea6dba383bac379 Mon Sep 17 00:00:00 2001
From: Zijun Zhao <zijunzhao at google.com>
Date: Thu, 4 Jan 2024 11:34:09 -0800
Subject: [PATCH 2/2] Add TEST_STD_VER condition

---
 .../diagnostics/ranges.nodiscard_extensions.compile.pass.cpp  | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/libcxx/test/libcxx/diagnostics/ranges.nodiscard_extensions.compile.pass.cpp b/libcxx/test/libcxx/diagnostics/ranges.nodiscard_extensions.compile.pass.cpp
index 9dc9c46ad89090..19e07b83079c78 100644
--- a/libcxx/test/libcxx/diagnostics/ranges.nodiscard_extensions.compile.pass.cpp
+++ b/libcxx/test/libcxx/diagnostics/ranges.nodiscard_extensions.compile.pass.cpp
@@ -15,6 +15,8 @@
 
 #include <algorithm>
 
+#include "test_macros.h"
+
 void test() {
   int range[1];
   int* iter = range;
@@ -28,8 +30,10 @@ void test() {
   std::ranges::binary_search(range, 1);
   std::ranges::binary_search(iter, iter, 1);
   std::ranges::clamp(1, 2, 3);
+#if TEST_STD_VER >= 23
   std::ranges::contains(range, 1);
   std::ranges::contains(iter, iter, 1);
+#endif
   std::ranges::count_if(range, pred);
   std::ranges::count_if(iter, iter, pred);
   std::ranges::count(range, 1);



More information about the libc-commits mailing list