Skip to content

[libc++][test] Fix unused and nodiscard warnings #73437

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>`.
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>`.
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>`.
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>`.
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@

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) {
LIBCPP_ASSERT(c.__invariants());
});
test_sequence_append_range<std::basic_string<char, std::char_traits<char>, Alloc>, Iter, Sent>(
[]([[maybe_unused]] auto&& c) { LIBCPP_ASSERT(c.__invariants()); });
});

return true;
Expand All @@ -35,9 +34,8 @@ 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) {
LIBCPP_ASSERT(c.__invariants());
});
test_sequence_append_range<std::basic_string<char, std::char_traits<char>, Alloc>, Iter, Sent>(
[]([[maybe_unused]] auto&& c) { LIBCPP_ASSERT(c.__invariants()); });
});
static_assert(test_constexpr());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@

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) {
LIBCPP_ASSERT(c.__invariants());
});
test_sequence_assign_range<std::basic_string<char, std::char_traits<char>, Alloc>, Iter, Sent>(
[]([[maybe_unused]] auto&& c) { LIBCPP_ASSERT(c.__invariants()); });
});

return true;
Expand All @@ -35,9 +34,8 @@ 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) {
LIBCPP_ASSERT(c.__invariants());
});
test_sequence_assign_range<std::basic_string<char, std::char_traits<char>, Alloc>, Iter, Sent>(
[]([[maybe_unused]] auto&& c) { LIBCPP_ASSERT(c.__invariants()); });
});
static_assert(test_constexpr());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@

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) {
LIBCPP_ASSERT(c.__invariants());
});
test_sequence_insert_range<std::basic_string<char, std::char_traits<char>, Alloc>, Iter, Sent>(
[]([[maybe_unused]] auto&& c) { LIBCPP_ASSERT(c.__invariants()); });
});

return true;
Expand All @@ -35,9 +34,8 @@ 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) {
LIBCPP_ASSERT(c.__invariants());
});
test_sequence_insert_range<std::basic_string<char, std::char_traits<char>, Alloc>, Iter, Sent>(
[]([[maybe_unused]] auto&& c) { LIBCPP_ASSERT(c.__invariants()); });
});
static_assert(test_constexpr());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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."});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
}
Expand Down
4 changes: 2 additions & 2 deletions libcxx/test/support/deduction_guides_sfinae_checks.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down