Skip to content

Commit 346a299

Browse files
[libc++][test] Fix unused and nodiscard warnings (#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.
1 parent dc8b055 commit 346a299

File tree

20 files changed

+34
-40
lines changed

20 files changed

+34
-40
lines changed

libcxx/test/std/algorithms/alg.sorting/alg.heap.operations/sort.heap/complexity.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ int main(int, char**) {
6161
const int debug_elements = std::min(100, n);
6262
// Multiplier 2 because of comp(a,b) comp(b, a) checks.
6363
const int debug_comparisons = 2 * (debug_elements + 1) * debug_elements;
64+
(void)debug_comparisons;
6465
std::shuffle(first, last, g);
6566
std::make_heap(first, last);
6667
// The exact stats of our current implementation are recorded here.
@@ -70,7 +71,6 @@ int main(int, char**) {
7071
LIBCPP_ASSERT(stats.moved <= 2 * n + n * logn);
7172
#if _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_DEBUG
7273
LIBCPP_ASSERT(stats.compared <= n * logn);
73-
(void)debug_comparisons;
7474
#else
7575
LIBCPP_ASSERT(stats.compared <= 2 * n * logn + debug_comparisons);
7676
#endif

libcxx/test/std/containers/sequences/deque/deque.cons/from_range.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
int main(int, char**) {
2121
for_all_iterators_and_allocators<int>([]<class Iter, class Sent, class Alloc>() {
22-
test_sequence_container<std::deque, int, Iter, Sent, Alloc>([](const auto& c) {
22+
test_sequence_container<std::deque, int, Iter, Sent, Alloc>([]([[maybe_unused]] const auto& c) {
2323
LIBCPP_ASSERT(c.__invariants());
2424
});
2525
});

libcxx/test/std/containers/sequences/deque/deque.modifiers/append_range.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ int main(int, char**) {
2626
static_assert(test_constraints_append_range<std::deque, int, double>());
2727

2828
for_all_iterators_and_allocators<int, const int*>([]<class Iter, class Sent, class Alloc>() {
29-
test_sequence_append_range<std::deque<int, Alloc>, Iter, Sent>([](auto&& c) {
29+
test_sequence_append_range<std::deque<int, Alloc>, Iter, Sent>([]([[maybe_unused]] auto&& c) {
3030
LIBCPP_ASSERT(c.__invariants());
3131
});
3232
});

libcxx/test/std/containers/sequences/deque/deque.modifiers/assign_range.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ int main(int, char**) {
2525
static_assert(test_constraints_assign_range<std::deque, int, double>());
2626

2727
for_all_iterators_and_allocators<int, const int*>([]<class Iter, class Sent, class Alloc>() {
28-
test_sequence_assign_range<std::deque<int, Alloc>, Iter, Sent>([](auto&& c) {
28+
test_sequence_assign_range<std::deque<int, Alloc>, Iter, Sent>([]([[maybe_unused]] auto&& c) {
2929
LIBCPP_ASSERT(c.__invariants());
3030
});
3131
});

libcxx/test/std/containers/sequences/deque/deque.modifiers/insert_range.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ int main(int, char**) {
2626
static_assert(test_constraints_insert_range<std::deque, int, double>());
2727

2828
for_all_iterators_and_allocators<int, const int*>([]<class Iter, class Sent, class Alloc>() {
29-
test_sequence_insert_range<std::deque<int, Alloc>, Iter, Sent>([](auto&& c) {
29+
test_sequence_insert_range<std::deque<int, Alloc>, Iter, Sent>([]([[maybe_unused]] auto&& c) {
3030
LIBCPP_ASSERT(c.__invariants());
3131
});
3232
});

libcxx/test/std/containers/sequences/deque/deque.modifiers/prepend_range.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ int main(int, char**) {
2626
static_assert(test_constraints_prepend_range<std::deque, int, double>());
2727

2828
for_all_iterators_and_allocators<int, const int*>([]<class Iter, class Sent, class Alloc>() {
29-
test_sequence_prepend_range<std::deque<int, Alloc>, Iter, Sent>([](auto&& c) {
29+
test_sequence_prepend_range<std::deque<int, Alloc>, Iter, Sent>([]([[maybe_unused]] auto&& c) {
3030
LIBCPP_ASSERT(c.__invariants());
3131
});
3232
});

libcxx/test/std/containers/sequences/vector.bool/append_range.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ constexpr bool test() {
2525
static_assert(test_constraints_append_range<std::vector, bool, char>());
2626

2727
for_all_iterators_and_allocators<bool, const int*>([]<class Iter, class Sent, class Alloc>() {
28-
test_sequence_append_range<std::vector<bool, Alloc>, Iter, Sent>([](auto&& c) {
28+
test_sequence_append_range<std::vector<bool, Alloc>, Iter, Sent>([]([[maybe_unused]] auto&& c) {
2929
LIBCPP_ASSERT(c.__invariants());
3030
// `is_contiguous_container_asan_correct` doesn't work on `vector<bool>`.
3131
});

libcxx/test/std/containers/sequences/vector.bool/assign_range.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ constexpr bool test() {
2525
static_assert(test_constraints_assign_range<std::vector, bool, char>());
2626

2727
for_all_iterators_and_allocators<bool, const int*>([]<class Iter, class Sent, class Alloc>() {
28-
test_sequence_assign_range<std::vector<bool, Alloc>, Iter, Sent>([](auto&& c) {
28+
test_sequence_assign_range<std::vector<bool, Alloc>, Iter, Sent>([]([[maybe_unused]] auto&& c) {
2929
LIBCPP_ASSERT(c.__invariants());
3030
// `is_contiguous_container_asan_correct` doesn't work on `vector<bool>`.
3131
});

libcxx/test/std/containers/sequences/vector.bool/construct_from_range.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
constexpr bool test() {
2020
for_all_iterators_and_allocators<bool>([]<class Iter, class Sent, class Alloc>() {
21-
test_vector_bool<Iter, Sent, Alloc>([](const auto& c) {
21+
test_vector_bool<Iter, Sent, Alloc>([]([[maybe_unused]] const auto& c) {
2222
LIBCPP_ASSERT(c.__invariants());
2323
// `is_contiguous_container_asan_correct` doesn't work on `vector<bool>`.
2424
});

libcxx/test/std/containers/sequences/vector.bool/insert_range.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ constexpr bool test() {
2525
static_assert(test_constraints_insert_range<std::vector, bool, char>());
2626

2727
for_all_iterators_and_allocators<bool, const int*>([]<class Iter, class Sent, class Alloc>() {
28-
test_sequence_insert_range<std::vector<bool, Alloc>, Iter, Sent>([](auto&& c) {
28+
test_sequence_insert_range<std::vector<bool, Alloc>, Iter, Sent>([]([[maybe_unused]] auto&& c) {
2929
LIBCPP_ASSERT(c.__invariants());
3030
// `is_contiguous_container_asan_correct` doesn't work on `vector<bool>`.
3131
});

0 commit comments

Comments
 (0)