[libcxx-commits] [libcxx] [libc++][test] Fix unused and nodiscard warnings (PR #73437)

Stephan T. Lavavej via libcxx-commits libcxx-commits at lists.llvm.org
Sun Nov 26 02:53:09 PST 2023


https://github.com/StephanTLavavej created https://github.com/llvm/llvm-project/pull/73437

Found while running libc++'s test suite with MSVC's STL.

This is structured into a series of commits for easier reviewing; I could also split this into smaller PRs if desired.

* Add void-casts for `invoke_r` calls to fix MSVC STL `[[nodiscard]]` warnings.
  + Our rationale is that if someone is calling `invoke_r<NonVoidType>`, it sure looks like they care about the return value.
* Add `[[maybe_unused]]` to silence `-Wunused-parameter` warnings.
  + This happens because the parameters are used within `LIBCPP_ASSERT`, which vanishes for MSVC's STL. This also motivates the following changes.
* Add `[[maybe_unused]]` to fix `-Wunused-variable` warnings.
* Always void-cast `debug_comparisons` to fix `-Wunused-variable` warnings.
  + As this was already unused with a void-cast in one `_LIBCPP_HARDENING_MODE` branch, I'm simply lifting it next to the variable definition.
* Add `[[maybe_unused]]` to fix `-Wunused-local-typedef` warnings.


>From 40187451f48d063e309d29610058ceceaffb9189 Mon Sep 17 00:00:00 2001
From: "Stephan T. Lavavej" <stl at nuwen.net>
Date: Sun, 19 Nov 2023 12:21:34 -0800
Subject: [PATCH 1/5] Add `[[maybe_unused]]` to silence `-Wunused-parameter`
 warnings.

---
 .../containers/sequences/deque/deque.cons/from_range.pass.cpp | 2 +-
 .../sequences/deque/deque.modifiers/append_range.pass.cpp     | 2 +-
 .../sequences/deque/deque.modifiers/assign_range.pass.cpp     | 2 +-
 .../sequences/deque/deque.modifiers/insert_range.pass.cpp     | 2 +-
 .../sequences/deque/deque.modifiers/prepend_range.pass.cpp    | 2 +-
 .../containers/sequences/vector.bool/append_range.pass.cpp    | 2 +-
 .../containers/sequences/vector.bool/assign_range.pass.cpp    | 2 +-
 .../sequences/vector.bool/construct_from_range.pass.cpp       | 2 +-
 .../containers/sequences/vector.bool/insert_range.pass.cpp    | 2 +-
 .../vector/vector.cons/construct_from_range.pass.cpp          | 2 +-
 .../sequences/vector/vector.modifiers/append_range.pass.cpp   | 2 +-
 .../sequences/vector/vector.modifiers/assign_range.pass.cpp   | 2 +-
 .../sequences/vector/vector.modifiers/insert_range.pass.cpp   | 2 +-
 .../string.modifiers/string_append/append_range.pass.cpp      | 4 ++--
 .../string.modifiers/string_assign/assign_range.pass.cpp      | 4 ++--
 .../string.modifiers/string_insert/insert_range.pass.cpp      | 4 ++--
 16 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/libcxx/test/std/containers/sequences/deque/deque.cons/from_range.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.cons/from_range.pass.cpp
index 0ea7c17d7659c42..cfc07ab7bc797d4 100644
--- a/libcxx/test/std/containers/sequences/deque/deque.cons/from_range.pass.cpp
+++ b/libcxx/test/std/containers/sequences/deque/deque.cons/from_range.pass.cpp
@@ -19,7 +19,7 @@
 
 int main(int, char**) {
   for_all_iterators_and_allocators<int>([]<class Iter, class Sent, class Alloc>() {
-    test_sequence_container<std::deque, int, Iter, Sent, Alloc>([](const auto& c) {
+    test_sequence_container<std::deque, int, Iter, Sent, Alloc>([]([[maybe_unused]] const auto& c) {
       LIBCPP_ASSERT(c.__invariants());
     });
   });
diff --git a/libcxx/test/std/containers/sequences/deque/deque.modifiers/append_range.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.modifiers/append_range.pass.cpp
index e6fe8c8b9e2326a..56a1d226db46f31 100644
--- a/libcxx/test/std/containers/sequences/deque/deque.modifiers/append_range.pass.cpp
+++ b/libcxx/test/std/containers/sequences/deque/deque.modifiers/append_range.pass.cpp
@@ -26,7 +26,7 @@ int main(int, char**) {
   static_assert(test_constraints_append_range<std::deque, int, double>());
 
   for_all_iterators_and_allocators<int, const int*>([]<class Iter, class Sent, class Alloc>() {
-    test_sequence_append_range<std::deque<int, Alloc>, Iter, Sent>([](auto&& c) {
+    test_sequence_append_range<std::deque<int, Alloc>, Iter, Sent>([]([[maybe_unused]] auto&& c) {
       LIBCPP_ASSERT(c.__invariants());
     });
   });
diff --git a/libcxx/test/std/containers/sequences/deque/deque.modifiers/assign_range.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.modifiers/assign_range.pass.cpp
index b830000518d5454..744e03a7b983e9e 100644
--- a/libcxx/test/std/containers/sequences/deque/deque.modifiers/assign_range.pass.cpp
+++ b/libcxx/test/std/containers/sequences/deque/deque.modifiers/assign_range.pass.cpp
@@ -25,7 +25,7 @@ int main(int, char**) {
   static_assert(test_constraints_assign_range<std::deque, int, double>());
 
   for_all_iterators_and_allocators<int, const int*>([]<class Iter, class Sent, class Alloc>() {
-    test_sequence_assign_range<std::deque<int, Alloc>, Iter, Sent>([](auto&& c) {
+    test_sequence_assign_range<std::deque<int, Alloc>, Iter, Sent>([]([[maybe_unused]] auto&& c) {
       LIBCPP_ASSERT(c.__invariants());
     });
   });
diff --git a/libcxx/test/std/containers/sequences/deque/deque.modifiers/insert_range.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.modifiers/insert_range.pass.cpp
index 7d0b3b9db28f80e..a5f5455297ad44e 100644
--- a/libcxx/test/std/containers/sequences/deque/deque.modifiers/insert_range.pass.cpp
+++ b/libcxx/test/std/containers/sequences/deque/deque.modifiers/insert_range.pass.cpp
@@ -26,7 +26,7 @@ int main(int, char**) {
   static_assert(test_constraints_insert_range<std::deque, int, double>());
 
   for_all_iterators_and_allocators<int, const int*>([]<class Iter, class Sent, class Alloc>() {
-    test_sequence_insert_range<std::deque<int, Alloc>, Iter, Sent>([](auto&& c) {
+    test_sequence_insert_range<std::deque<int, Alloc>, Iter, Sent>([]([[maybe_unused]] auto&& c) {
       LIBCPP_ASSERT(c.__invariants());
     });
   });
diff --git a/libcxx/test/std/containers/sequences/deque/deque.modifiers/prepend_range.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.modifiers/prepend_range.pass.cpp
index 08c9c02a8b69939..3154cd389d2f0f4 100644
--- a/libcxx/test/std/containers/sequences/deque/deque.modifiers/prepend_range.pass.cpp
+++ b/libcxx/test/std/containers/sequences/deque/deque.modifiers/prepend_range.pass.cpp
@@ -26,7 +26,7 @@ int main(int, char**) {
   static_assert(test_constraints_prepend_range<std::deque, int, double>());
 
   for_all_iterators_and_allocators<int, const int*>([]<class Iter, class Sent, class Alloc>() {
-    test_sequence_prepend_range<std::deque<int, Alloc>, Iter, Sent>([](auto&& c) {
+    test_sequence_prepend_range<std::deque<int, Alloc>, Iter, Sent>([]([[maybe_unused]] auto&& c) {
       LIBCPP_ASSERT(c.__invariants());
     });
   });
diff --git a/libcxx/test/std/containers/sequences/vector.bool/append_range.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/append_range.pass.cpp
index e76f9bcd3110acf..aafeec766944905 100644
--- a/libcxx/test/std/containers/sequences/vector.bool/append_range.pass.cpp
+++ b/libcxx/test/std/containers/sequences/vector.bool/append_range.pass.cpp
@@ -25,7 +25,7 @@ constexpr bool test() {
   static_assert(test_constraints_append_range<std::vector, bool, char>());
 
   for_all_iterators_and_allocators<bool, const int*>([]<class Iter, class Sent, class Alloc>() {
-    test_sequence_append_range<std::vector<bool, Alloc>, Iter, Sent>([](auto&& c) {
+    test_sequence_append_range<std::vector<bool, Alloc>, Iter, Sent>([]([[maybe_unused]] auto&& c) {
       LIBCPP_ASSERT(c.__invariants());
       // `is_contiguous_container_asan_correct` doesn't work on `vector<bool>`.
     });
diff --git a/libcxx/test/std/containers/sequences/vector.bool/assign_range.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/assign_range.pass.cpp
index 6ae5aa46d6cc142..e5d0454a844d5a8 100644
--- a/libcxx/test/std/containers/sequences/vector.bool/assign_range.pass.cpp
+++ b/libcxx/test/std/containers/sequences/vector.bool/assign_range.pass.cpp
@@ -25,7 +25,7 @@ constexpr bool test() {
   static_assert(test_constraints_assign_range<std::vector, bool, char>());
 
   for_all_iterators_and_allocators<bool, const int*>([]<class Iter, class Sent, class Alloc>() {
-    test_sequence_assign_range<std::vector<bool, Alloc>, Iter, Sent>([](auto&& c) {
+    test_sequence_assign_range<std::vector<bool, Alloc>, Iter, Sent>([]([[maybe_unused]] auto&& c) {
       LIBCPP_ASSERT(c.__invariants());
       // `is_contiguous_container_asan_correct` doesn't work on `vector<bool>`.
     });
diff --git a/libcxx/test/std/containers/sequences/vector.bool/construct_from_range.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/construct_from_range.pass.cpp
index d1f0bf06ed57550..03f3100b928833a 100644
--- a/libcxx/test/std/containers/sequences/vector.bool/construct_from_range.pass.cpp
+++ b/libcxx/test/std/containers/sequences/vector.bool/construct_from_range.pass.cpp
@@ -18,7 +18,7 @@
 
 constexpr bool test() {
   for_all_iterators_and_allocators<bool>([]<class Iter, class Sent, class Alloc>() {
-    test_vector_bool<Iter, Sent, Alloc>([](const auto& c) {
+    test_vector_bool<Iter, Sent, Alloc>([]([[maybe_unused]] const auto& c) {
       LIBCPP_ASSERT(c.__invariants());
       // `is_contiguous_container_asan_correct` doesn't work on `vector<bool>`.
     });
diff --git a/libcxx/test/std/containers/sequences/vector.bool/insert_range.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/insert_range.pass.cpp
index 260a1037173e14b..65d085fa1f08325 100644
--- a/libcxx/test/std/containers/sequences/vector.bool/insert_range.pass.cpp
+++ b/libcxx/test/std/containers/sequences/vector.bool/insert_range.pass.cpp
@@ -25,7 +25,7 @@ constexpr bool test() {
   static_assert(test_constraints_insert_range<std::vector, bool, char>());
 
   for_all_iterators_and_allocators<bool, const int*>([]<class Iter, class Sent, class Alloc>() {
-    test_sequence_insert_range<std::vector<bool, Alloc>, Iter, Sent>([](auto&& c) {
+    test_sequence_insert_range<std::vector<bool, Alloc>, Iter, Sent>([]([[maybe_unused]] auto&& c) {
       LIBCPP_ASSERT(c.__invariants());
       // `is_contiguous_container_asan_correct` doesn't work on `vector<bool>`.
     });
diff --git a/libcxx/test/std/containers/sequences/vector/vector.cons/construct_from_range.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.cons/construct_from_range.pass.cpp
index 2acdcc35da6f4f6..5fb2b46f7e94208 100644
--- a/libcxx/test/std/containers/sequences/vector/vector.cons/construct_from_range.pass.cpp
+++ b/libcxx/test/std/containers/sequences/vector/vector.cons/construct_from_range.pass.cpp
@@ -19,7 +19,7 @@
 
 constexpr bool test() {
   for_all_iterators_and_allocators<int>([]<class Iter, class Sent, class Alloc>() {
-    test_sequence_container<std::vector, int, Iter, Sent, Alloc>([](const auto& c) {
+    test_sequence_container<std::vector, int, Iter, Sent, Alloc>([]([[maybe_unused]] const auto& c) {
       LIBCPP_ASSERT(c.__invariants());
       LIBCPP_ASSERT(is_contiguous_container_asan_correct(c));
     });
diff --git a/libcxx/test/std/containers/sequences/vector/vector.modifiers/append_range.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.modifiers/append_range.pass.cpp
index 0a9453428753444..69e6df6fcffa851 100644
--- a/libcxx/test/std/containers/sequences/vector/vector.modifiers/append_range.pass.cpp
+++ b/libcxx/test/std/containers/sequences/vector/vector.modifiers/append_range.pass.cpp
@@ -27,7 +27,7 @@ constexpr bool test() {
   static_assert(test_constraints_append_range<std::vector, int, double>());
 
   for_all_iterators_and_allocators<int, const int*>([]<class Iter, class Sent, class Alloc>() {
-    test_sequence_append_range<std::vector<int, Alloc>, Iter, Sent>([](auto&& c) {
+    test_sequence_append_range<std::vector<int, Alloc>, Iter, Sent>([]([[maybe_unused]] auto&& c) {
       LIBCPP_ASSERT(c.__invariants());
       LIBCPP_ASSERT(is_contiguous_container_asan_correct(c));
     });
diff --git a/libcxx/test/std/containers/sequences/vector/vector.modifiers/assign_range.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.modifiers/assign_range.pass.cpp
index 891c6df4474dc02..8ab3dc10aed9902 100644
--- a/libcxx/test/std/containers/sequences/vector/vector.modifiers/assign_range.pass.cpp
+++ b/libcxx/test/std/containers/sequences/vector/vector.modifiers/assign_range.pass.cpp
@@ -27,7 +27,7 @@ constexpr bool test() {
   static_assert(test_constraints_assign_range<std::vector, int, double>());
 
   for_all_iterators_and_allocators<int, const int*>([]<class Iter, class Sent, class Alloc>() {
-    test_sequence_assign_range<std::vector<int, Alloc>, Iter, Sent>([](auto&& c) {
+    test_sequence_assign_range<std::vector<int, Alloc>, Iter, Sent>([]([[maybe_unused]] auto&& c) {
       LIBCPP_ASSERT(c.__invariants());
       LIBCPP_ASSERT(is_contiguous_container_asan_correct(c));
     });
diff --git a/libcxx/test/std/containers/sequences/vector/vector.modifiers/insert_range.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.modifiers/insert_range.pass.cpp
index 3b900ce73e98f56..0e26cb1546277bd 100644
--- a/libcxx/test/std/containers/sequences/vector/vector.modifiers/insert_range.pass.cpp
+++ b/libcxx/test/std/containers/sequences/vector/vector.modifiers/insert_range.pass.cpp
@@ -26,7 +26,7 @@
 
 constexpr bool test() {
   for_all_iterators_and_allocators<int, const int*>([]<class Iter, class Sent, class Alloc>() {
-    test_sequence_insert_range<std::vector<int, Alloc>, Iter, Sent>([](auto&& c) {
+    test_sequence_insert_range<std::vector<int, Alloc>, Iter, Sent>([]([[maybe_unused]] auto&& c) {
       LIBCPP_ASSERT(c.__invariants());
       LIBCPP_ASSERT(is_contiguous_container_asan_correct(c));
     });
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/append_range.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/append_range.pass.cpp
index 68327f65bdb381a..701282bcefaf711 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/append_range.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/append_range.pass.cpp
@@ -23,7 +23,7 @@
 
 constexpr bool test_constexpr() {
   for_all_iterators_and_allocators_constexpr<char, const char*>([]<class Iter, class Sent, class Alloc>() {
-    test_sequence_append_range<std::basic_string<char, std::char_traits<char>, Alloc>, Iter, Sent>([](auto&& c) {
+    test_sequence_append_range<std::basic_string<char, std::char_traits<char>, Alloc>, Iter, Sent>([]([[maybe_unused]] auto&& c) {
       LIBCPP_ASSERT(c.__invariants());
     });
   });
@@ -35,7 +35,7 @@ int main(int, char**) {
   static_assert(test_constraints_append_range<std::basic_string, char, int>());
 
   for_all_iterators_and_allocators<char, const char*>([]<class Iter, class Sent, class Alloc>() {
-    test_sequence_append_range<std::basic_string<char, std::char_traits<char>, Alloc>, Iter, Sent>([](auto&& c) {
+    test_sequence_append_range<std::basic_string<char, std::char_traits<char>, Alloc>, Iter, Sent>([]([[maybe_unused]] auto&& c) {
       LIBCPP_ASSERT(c.__invariants());
     });
   });
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/assign_range.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/assign_range.pass.cpp
index 5c43eeaf39dfff4..c11a97f3db23579 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/assign_range.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/assign_range.pass.cpp
@@ -23,7 +23,7 @@
 
 constexpr bool test_constexpr() {
   for_all_iterators_and_allocators_constexpr<char, const char*>([]<class Iter, class Sent, class Alloc>() {
-    test_sequence_assign_range<std::basic_string<char, std::char_traits<char>, Alloc>, Iter, Sent>([](auto&& c) {
+    test_sequence_assign_range<std::basic_string<char, std::char_traits<char>, Alloc>, Iter, Sent>([]([[maybe_unused]] auto&& c) {
       LIBCPP_ASSERT(c.__invariants());
     });
   });
@@ -35,7 +35,7 @@ int main(int, char**) {
   static_assert(test_constraints_assign_range<std::basic_string, char, int>());
 
   for_all_iterators_and_allocators<char, const char*>([]<class Iter, class Sent, class Alloc>() {
-    test_sequence_assign_range<std::basic_string<char, std::char_traits<char>, Alloc>, Iter, Sent>([](auto&& c) {
+    test_sequence_assign_range<std::basic_string<char, std::char_traits<char>, Alloc>, Iter, Sent>([]([[maybe_unused]] auto&& c) {
       LIBCPP_ASSERT(c.__invariants());
     });
   });
diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/insert_range.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/insert_range.pass.cpp
index aefe73a9a507f22..e66a870d0b5e9bc 100644
--- a/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/insert_range.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_insert/insert_range.pass.cpp
@@ -23,7 +23,7 @@
 
 constexpr bool test_constexpr() {
   for_all_iterators_and_allocators_constexpr<char, const char*>([]<class Iter, class Sent, class Alloc>() {
-    test_sequence_insert_range<std::basic_string<char, std::char_traits<char>, Alloc>, Iter, Sent>([](auto&& c) {
+    test_sequence_insert_range<std::basic_string<char, std::char_traits<char>, Alloc>, Iter, Sent>([]([[maybe_unused]] auto&& c) {
       LIBCPP_ASSERT(c.__invariants());
     });
   });
@@ -35,7 +35,7 @@ int main(int, char**) {
   static_assert(test_constraints_insert_range<std::basic_string, char, int>());
 
   for_all_iterators_and_allocators<char, const char*>([]<class Iter, class Sent, class Alloc>() {
-    test_sequence_insert_range<std::basic_string<char, std::char_traits<char>, Alloc>, Iter, Sent>([](auto&& c) {
+    test_sequence_insert_range<std::basic_string<char, std::char_traits<char>, Alloc>, Iter, Sent>([]([[maybe_unused]] auto&& c) {
       LIBCPP_ASSERT(c.__invariants());
     });
   });

>From 9e4785dbac7018a3e8503e9482442c27ace151f6 Mon Sep 17 00:00:00 2001
From: "Stephan T. Lavavej" <stl at nuwen.net>
Date: Sun, 19 Nov 2023 12:26:14 -0800
Subject: [PATCH 2/5] Add `[[maybe_unused]]` to fix `-Wunused-variable`
 warnings.

---
 .../std/thread/futures/futures.future_error/what.pass.cpp | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libcxx/test/std/thread/futures/futures.future_error/what.pass.cpp b/libcxx/test/std/thread/futures/futures.future_error/what.pass.cpp
index fba2bd80d7f89a0..2e971a940c509ce 100644
--- a/libcxx/test/std/thread/futures/futures.future_error/what.pass.cpp
+++ b/libcxx/test/std/thread/futures/futures.future_error/what.pass.cpp
@@ -38,24 +38,24 @@ int main(int, char**) {
 #if TEST_STD_VER >= 17
   {
     std::future_error const f(std::future_errc::broken_promise);
-    char const* what = f.what();
+    [[maybe_unused]] char const* what = f.what();
     LIBCPP_ASSERT(what == std::string_view{"The associated promise has been destructed prior "
                                            "to the associated state becoming ready."});
   }
   {
     std::future_error f(std::future_errc::future_already_retrieved);
-    char const* what = f.what();
+    [[maybe_unused]] char const* what = f.what();
     LIBCPP_ASSERT(what == std::string_view{"The future has already been retrieved from "
                                            "the promise or packaged_task."});
   }
   {
     std::future_error f(std::future_errc::promise_already_satisfied);
-    char const* what = f.what();
+    [[maybe_unused]] char const* what = f.what();
     LIBCPP_ASSERT(what == std::string_view{"The state of the promise has already been set."});
   }
   {
     std::future_error f(std::future_errc::no_state);
-    char const* what = f.what();
+    [[maybe_unused]] char const* what = f.what();
     LIBCPP_ASSERT(what == std::string_view{"Operation not permitted on an object without "
                                            "an associated state."});
   }

>From 201d652d5f2618e51ccb507dad2f7e5e9e9c6404 Mon Sep 17 00:00:00 2001
From: "Stephan T. Lavavej" <stl at nuwen.net>
Date: Sun, 19 Nov 2023 12:29:03 -0800
Subject: [PATCH 3/5] Always void-cast `debug_comparisons` to fix
 `-Wunused-variable` warnings.

---
 .../alg.heap.operations/sort.heap/complexity.pass.cpp           | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/sort.heap/complexity.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/sort.heap/complexity.pass.cpp
index dbf7b534069517a..3b7c0ae0b80f08b 100644
--- a/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/sort.heap/complexity.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/sort.heap/complexity.pass.cpp
@@ -61,6 +61,7 @@ int main(int, char**) {
     const int debug_elements = std::min(100, n);
     // Multiplier 2 because of comp(a,b) comp(b, a) checks.
     const int debug_comparisons = 2 * (debug_elements + 1) * debug_elements;
+    (void)debug_comparisons;
     std::shuffle(first, last, g);
     std::make_heap(first, last);
     // The exact stats of our current implementation are recorded here.
@@ -70,7 +71,6 @@ int main(int, char**) {
     LIBCPP_ASSERT(stats.moved <= 2 * n + n * logn);
 #if _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_DEBUG
     LIBCPP_ASSERT(stats.compared <= n * logn);
-    (void)debug_comparisons;
 #else
     LIBCPP_ASSERT(stats.compared <= 2 * n * logn + debug_comparisons);
 #endif

>From 9ef8873041a813f7b4ae34b13639a82cd295281c Mon Sep 17 00:00:00 2001
From: "Stephan T. Lavavej" <stl at nuwen.net>
Date: Sun, 19 Nov 2023 12:32:19 -0800
Subject: [PATCH 4/5] Add `[[maybe_unused]]` to fix `-Wunused-local-typedef`
 warnings.

---
 libcxx/test/support/deduction_guides_sfinae_checks.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libcxx/test/support/deduction_guides_sfinae_checks.h b/libcxx/test/support/deduction_guides_sfinae_checks.h
index 8d1365848eafc48..8b715da5a34e25f 100644
--- a/libcxx/test/support/deduction_guides_sfinae_checks.h
+++ b/libcxx/test/support/deduction_guides_sfinae_checks.h
@@ -116,10 +116,10 @@ constexpr void SequenceContainerDeductionGuidesSfinaeAway() {
 template<template<typename ...> class Container, typename InstantiatedContainer>
 constexpr void ContainerAdaptorDeductionGuidesSfinaeAway() {
   using T = typename InstantiatedContainer::value_type;
-  using Alloc = std::allocator<T>;
+  using Alloc [[maybe_unused]] = std::allocator<T>;
   using Iter = T*;
 
-  using BadIter = int;
+  using BadIter [[maybe_unused]] = int;
   using BadAlloc = Empty;
 
   // (container) -- no constraints.

>From fa7af926d893140d66749dd14bad220d8f433a3b Mon Sep 17 00:00:00 2001
From: "Stephan T. Lavavej" <stl at nuwen.net>
Date: Sun, 19 Nov 2023 12:33:30 -0800
Subject: [PATCH 5/5] Add void-casts for invoke_r calls to fix MSVC STL
 nodiscard warnings.

Our rationale is that if someone is calling invoke_r<NonVoidType>, it sure looks like they care about the return value.
---
 .../utilities/function.objects/func.invoke/invoke_r.pass.cpp  | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libcxx/test/std/utilities/function.objects/func.invoke/invoke_r.pass.cpp b/libcxx/test/std/utilities/function.objects/func.invoke/invoke_r.pass.cpp
index af4c0baf8c60c59..8a08d3636d1e277 100644
--- a/libcxx/test/std/utilities/function.objects/func.invoke/invoke_r.pass.cpp
+++ b/libcxx/test/std/utilities/function.objects/func.invoke/invoke_r.pass.cpp
@@ -91,7 +91,7 @@ constexpr bool test() {
         {
             bool was_called = false;
             auto f = [&](NonCopyable) -> int { was_called = true; return 0; };
-            std::invoke_r<int>(f, NonCopyable());
+            (void)std::invoke_r<int>(f, NonCopyable());
             assert(was_called);
         }
         // Forward function object, with void return
@@ -111,7 +111,7 @@ constexpr bool test() {
                 constexpr int operator()() && { was_called = true; return 0; }
             };
             bool was_called = false;
-            std::invoke_r<int>(MoveOnlyIntFunction{was_called});
+            (void)std::invoke_r<int>(MoveOnlyIntFunction{was_called});
             assert(was_called);
         }
     }



More information about the libcxx-commits mailing list