From 164c204a19f7859d570003d4c5e82faf48cb65a9 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Tue, 5 Dec 2023 06:46:41 -0800 Subject: [PATCH] [libc++][test] Fix simple warnings (#74186) Found while running libc++'s tests with MSVC's STL. This fixes 3 kinds of warnings: - Add void-casts to fix `-Wunused-variable` warnings. - Avoid sign/truncation warnings in `ConvertibleToIntegral.h`. - Add `TEST_STD_AT_LEAST_23_OR_RUNTIME_EVALUATED` to avoid mixing preprocessor and runtime tests. - Cleanup: Add `TEST_STD_AT_LEAST_20_OR_RUNTIME_EVALUATED` for consistency. --- .../alg.modifying.operations/alg.move/move.pass.cpp | 2 +- .../alg.move/move_backward.pass.cpp | 2 +- .../alg.nonmodifying/alg.count/count.pass.cpp | 2 +- .../containers/views/mdspan/ConvertibleToIntegral.h | 8 ++++---- .../test/std/numerics/rand/rand.device/ctor.pass.cpp | 1 + .../string.view.comparison/equal.pass.cpp | 4 ++-- .../string.view.comparison/greater.pass.cpp | 4 ++-- .../string.view.comparison/greater_equal.pass.cpp | 4 ++-- .../string.view/string.view.comparison/less.pass.cpp | 4 ++-- .../string.view.comparison/less_equal.pass.cpp | 4 ++-- .../string.view.comparison/not_equal.pass.cpp | 4 ++-- .../thread.lock/thread.lock.scoped/mutex.pass.cpp | 1 + .../thread.shared_mutex.class/default.pass.cpp | 3 ++- libcxx/test/support/test_macros.h | 12 ++++++++++++ 14 files changed, 35 insertions(+), 20 deletions(-) diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.move/move.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.move/move.pass.cpp index ce5cf0560fc81a..b1ad6873bc5e5a 100644 --- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.move/move.pass.cpp +++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.move/move.pass.cpp @@ -94,7 +94,7 @@ struct Test1OutIters { TEST_CONSTEXPR_CXX20 bool test() { types::for_each(types::cpp17_input_iterator_list(), TestOutIters()); - if (TEST_STD_VER >= 23 || !TEST_IS_CONSTANT_EVALUATED) + if (TEST_STD_AT_LEAST_23_OR_RUNTIME_EVALUATED) types::for_each(types::cpp17_input_iterator_list*>(), Test1OutIters()); { // Make sure that padding bits aren't copied diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.move/move_backward.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.move/move_backward.pass.cpp index 2ed4d37b9dbe64..61dea47b510716 100644 --- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.move/move_backward.pass.cpp +++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.move/move_backward.pass.cpp @@ -92,7 +92,7 @@ struct Test1OutIters { TEST_CONSTEXPR_CXX20 bool test() { types::for_each(types::bidirectional_iterator_list(), TestOutIters()); - if (TEST_STD_VER >= 23 || !TEST_IS_CONSTANT_EVALUATED) + if (TEST_STD_AT_LEAST_23_OR_RUNTIME_EVALUATED) types::for_each(types::bidirectional_iterator_list*>(), Test1OutIters()); { // Make sure that padding bits aren't copied diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.count/count.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.count/count.pass.cpp index cc832febdba751..904100c1cf0bb1 100644 --- a/libcxx/test/std/algorithms/alg.nonmodifying/alg.count/count.pass.cpp +++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.count/count.pass.cpp @@ -38,7 +38,7 @@ struct Test { TEST_CONSTEXPR_CXX20 bool test() { types::for_each(types::cpp17_input_iterator_list(), Test()); - if (!TEST_IS_CONSTANT_EVALUATED || TEST_STD_VER >= 20) { + if (TEST_STD_AT_LEAST_20_OR_RUNTIME_EVALUATED) { std::vector vec(256 + 64); for (ptrdiff_t i = 0; i != 256; ++i) { for (size_t offset = 0; offset != 64; ++offset) { diff --git a/libcxx/test/std/containers/views/mdspan/ConvertibleToIntegral.h b/libcxx/test/std/containers/views/mdspan/ConvertibleToIntegral.h index 470f5d8e724648..0ca5c330a390e4 100644 --- a/libcxx/test/std/containers/views/mdspan/ConvertibleToIntegral.h +++ b/libcxx/test/std/containers/views/mdspan/ConvertibleToIntegral.h @@ -16,8 +16,8 @@ struct IntType { constexpr bool operator==(const IntType& rhs) const { return val == rhs.val; } constexpr operator int() const noexcept { return val; } - constexpr operator unsigned char() const { return val; } - constexpr operator signed char() const noexcept { return val; } + constexpr operator unsigned char() const { return static_cast(val); } + constexpr operator signed char() const noexcept { return static_cast(val); } }; // only non-const convertible @@ -28,8 +28,8 @@ struct IntTypeNC { constexpr bool operator==(const IntType& rhs) const { return val == rhs.val; } constexpr operator int() noexcept { return val; } - constexpr operator unsigned() { return val; } - constexpr operator char() noexcept { return val; } + constexpr operator unsigned() { return static_cast(val); } + constexpr operator char() noexcept { return static_cast(val); } }; // weird configurability of convertibility to int diff --git a/libcxx/test/std/numerics/rand/rand.device/ctor.pass.cpp b/libcxx/test/std/numerics/rand/rand.device/ctor.pass.cpp index a2d46ab1b94c7a..796ab41716dd5f 100644 --- a/libcxx/test/std/numerics/rand/rand.device/ctor.pass.cpp +++ b/libcxx/test/std/numerics/rand/rand.device/ctor.pass.cpp @@ -61,6 +61,7 @@ void check_random_device_invalid(const std::string &token) { int main(int, char**) { { std::random_device r; + (void)r; } // Check the validity of various tokens { diff --git a/libcxx/test/std/strings/string.view/string.view.comparison/equal.pass.cpp b/libcxx/test/std/strings/string.view/string.view.comparison/equal.pass.cpp index 4f00bd7f6edf19..fc99df4072131b 100644 --- a/libcxx/test/std/strings/string.view/string.view.comparison/equal.pass.cpp +++ b/libcxx/test/std/strings/string.view/string.view.comparison/equal.pass.cpp @@ -51,7 +51,7 @@ TEST_CONSTEXPR_CXX14 bool test() { assert((ConvertibleTo(v[i]) == v[j]) == expected); assert((v[i] == ConvertibleTo(v[j])) == expected); - if (!TEST_IS_CONSTANT_EVALUATED || TEST_STD_VER >= 20) { + if (TEST_STD_AT_LEAST_20_OR_RUNTIME_EVALUATED) { assert((std::basic_string(v[i]) == v[j]) == expected); assert((v[i] == std::basic_string(v[j])) == expected); } @@ -72,7 +72,7 @@ TEST_CONSTEXPR_CXX14 bool test() { assert((abc.data() == abc0def) == false); assert((abc0def == abc.data()) == false); - if (!TEST_IS_CONSTANT_EVALUATED || TEST_STD_VER >= 20) { + if (TEST_STD_AT_LEAST_20_OR_RUNTIME_EVALUATED) { assert((std::basic_string(abc) == abc0def) == false); assert((abc0def == std::basic_string(abc)) == false); } diff --git a/libcxx/test/std/strings/string.view/string.view.comparison/greater.pass.cpp b/libcxx/test/std/strings/string.view/string.view.comparison/greater.pass.cpp index b965c155ec51ba..fd3a438167994a 100644 --- a/libcxx/test/std/strings/string.view/string.view.comparison/greater.pass.cpp +++ b/libcxx/test/std/strings/string.view/string.view.comparison/greater.pass.cpp @@ -51,7 +51,7 @@ TEST_CONSTEXPR_CXX14 bool test() { assert((ConvertibleTo(v[i]) > v[j]) == expected); assert((v[i] > ConvertibleTo(v[j])) == expected); - if (!TEST_IS_CONSTANT_EVALUATED || TEST_STD_VER >= 20) { + if (TEST_STD_AT_LEAST_20_OR_RUNTIME_EVALUATED) { assert((std::basic_string(v[i]) > v[j]) == expected); assert((v[i] > std::basic_string(v[j])) == expected); } @@ -72,7 +72,7 @@ TEST_CONSTEXPR_CXX14 bool test() { assert((abc.data() > abc0def) == false); assert((abc0def > abc.data()) == true); - if (!TEST_IS_CONSTANT_EVALUATED || TEST_STD_VER >= 20) { + if (TEST_STD_AT_LEAST_20_OR_RUNTIME_EVALUATED) { assert((std::basic_string(abc) > abc0def) == false); assert((abc0def > std::basic_string(abc)) == true); } diff --git a/libcxx/test/std/strings/string.view/string.view.comparison/greater_equal.pass.cpp b/libcxx/test/std/strings/string.view/string.view.comparison/greater_equal.pass.cpp index 435e7db7731998..0d9081e1c01d88 100644 --- a/libcxx/test/std/strings/string.view/string.view.comparison/greater_equal.pass.cpp +++ b/libcxx/test/std/strings/string.view/string.view.comparison/greater_equal.pass.cpp @@ -51,7 +51,7 @@ TEST_CONSTEXPR_CXX14 bool test() { assert((ConvertibleTo(v[i]) >= v[j]) == expected); assert((v[i] >= ConvertibleTo(v[j])) == expected); - if (!TEST_IS_CONSTANT_EVALUATED || TEST_STD_VER >= 20) { + if (TEST_STD_AT_LEAST_20_OR_RUNTIME_EVALUATED) { assert((std::basic_string(v[i]) >= v[j]) == expected); assert((v[i] >= std::basic_string(v[j])) == expected); } @@ -72,7 +72,7 @@ TEST_CONSTEXPR_CXX14 bool test() { assert((abc.data() >= abc0def) == false); assert((abc0def >= abc.data()) == true); - if (!TEST_IS_CONSTANT_EVALUATED || TEST_STD_VER >= 20) { + if (TEST_STD_AT_LEAST_20_OR_RUNTIME_EVALUATED) { assert((std::basic_string(abc) >= abc0def) == false); assert((abc0def >= std::basic_string(abc)) == true); } diff --git a/libcxx/test/std/strings/string.view/string.view.comparison/less.pass.cpp b/libcxx/test/std/strings/string.view/string.view.comparison/less.pass.cpp index 7461b05ce30853..bb61b1df193e6a 100644 --- a/libcxx/test/std/strings/string.view/string.view.comparison/less.pass.cpp +++ b/libcxx/test/std/strings/string.view/string.view.comparison/less.pass.cpp @@ -51,7 +51,7 @@ TEST_CONSTEXPR_CXX14 bool test() { assert((ConvertibleTo(v[i]) < v[j]) == expected); assert((v[i] < ConvertibleTo(v[j])) == expected); - if (!TEST_IS_CONSTANT_EVALUATED || TEST_STD_VER >= 20) { + if (TEST_STD_AT_LEAST_20_OR_RUNTIME_EVALUATED) { assert((std::basic_string(v[i]) < v[j]) == expected); assert((v[i] < std::basic_string(v[j])) == expected); } @@ -72,7 +72,7 @@ TEST_CONSTEXPR_CXX14 bool test() { assert((abc.data() < abc0def) == true); assert((abc0def < abc.data()) == false); - if (!TEST_IS_CONSTANT_EVALUATED || TEST_STD_VER >= 20) { + if (TEST_STD_AT_LEAST_20_OR_RUNTIME_EVALUATED) { assert((std::basic_string(abc) < abc0def) == true); assert((abc0def < std::basic_string(abc)) == false); } diff --git a/libcxx/test/std/strings/string.view/string.view.comparison/less_equal.pass.cpp b/libcxx/test/std/strings/string.view/string.view.comparison/less_equal.pass.cpp index 3192db0dc7d7d2..d91e112d6dabf3 100644 --- a/libcxx/test/std/strings/string.view/string.view.comparison/less_equal.pass.cpp +++ b/libcxx/test/std/strings/string.view/string.view.comparison/less_equal.pass.cpp @@ -51,7 +51,7 @@ TEST_CONSTEXPR_CXX14 bool test() { assert((ConvertibleTo(v[i]) <= v[j]) == expected); assert((v[i] <= ConvertibleTo(v[j])) == expected); - if (!TEST_IS_CONSTANT_EVALUATED || TEST_STD_VER >= 20) { + if (TEST_STD_AT_LEAST_20_OR_RUNTIME_EVALUATED) { assert((std::basic_string(v[i]) <= v[j]) == expected); assert((v[i] <= std::basic_string(v[j])) == expected); } @@ -72,7 +72,7 @@ TEST_CONSTEXPR_CXX14 bool test() { assert((abc.data() <= abc0def) == true); assert((abc0def <= abc.data()) == false); - if (!TEST_IS_CONSTANT_EVALUATED || TEST_STD_VER >= 20) { + if (TEST_STD_AT_LEAST_20_OR_RUNTIME_EVALUATED) { assert((std::basic_string(abc) <= abc0def) == true); assert((abc0def <= std::basic_string(abc)) == false); } diff --git a/libcxx/test/std/strings/string.view/string.view.comparison/not_equal.pass.cpp b/libcxx/test/std/strings/string.view/string.view.comparison/not_equal.pass.cpp index 0082a568393313..a4c8be9f878f0d 100644 --- a/libcxx/test/std/strings/string.view/string.view.comparison/not_equal.pass.cpp +++ b/libcxx/test/std/strings/string.view/string.view.comparison/not_equal.pass.cpp @@ -51,7 +51,7 @@ TEST_CONSTEXPR_CXX14 bool test() { assert((ConvertibleTo(v[i]) != v[j]) == expected); assert((v[i] != ConvertibleTo(v[j])) == expected); - if (!TEST_IS_CONSTANT_EVALUATED || TEST_STD_VER >= 20) { + if (TEST_STD_AT_LEAST_20_OR_RUNTIME_EVALUATED) { assert((std::basic_string(v[i]) != v[j]) == expected); assert((v[i] != std::basic_string(v[j])) == expected); } @@ -72,7 +72,7 @@ TEST_CONSTEXPR_CXX14 bool test() { assert((abc.data() != abc0def) == true); assert((abc0def != abc.data()) == true); - if (!TEST_IS_CONSTANT_EVALUATED || TEST_STD_VER >= 20) { + if (TEST_STD_AT_LEAST_20_OR_RUNTIME_EVALUATED) { assert((std::basic_string(abc) != abc0def) == true); assert((abc0def != std::basic_string(abc)) == true); } diff --git a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.scoped/mutex.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.scoped/mutex.pass.cpp index 48a96f90254e3e..f953fa4f8d6df2 100644 --- a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.scoped/mutex.pass.cpp +++ b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.scoped/mutex.pass.cpp @@ -66,6 +66,7 @@ int main(int, char**) { using LG = std::scoped_lock<>; LG lg; + (void)lg; } { using LG = std::scoped_lock; diff --git a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/default.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/default.pass.cpp index 91320a52b62aea..5504645bb31f96 100644 --- a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/default.pass.cpp +++ b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/default.pass.cpp @@ -22,6 +22,7 @@ int main(int, char**) { std::shared_mutex m; + (void)m; - return 0; + return 0; } diff --git a/libcxx/test/support/test_macros.h b/libcxx/test/support/test_macros.h index f3c6d8080ff6d8..02678d987d265f 100644 --- a/libcxx/test/support/test_macros.h +++ b/libcxx/test/support/test_macros.h @@ -151,6 +151,18 @@ # define TEST_IS_CONSTANT_EVALUATED false #endif +#if TEST_STD_VER >= 23 +# define TEST_STD_AT_LEAST_23_OR_RUNTIME_EVALUATED true +#else +# define TEST_STD_AT_LEAST_23_OR_RUNTIME_EVALUATED (!TEST_IS_CONSTANT_EVALUATED) +#endif + +#if TEST_STD_VER >= 20 +# define TEST_STD_AT_LEAST_20_OR_RUNTIME_EVALUATED true +#else +# define TEST_STD_AT_LEAST_20_OR_RUNTIME_EVALUATED (!TEST_IS_CONSTANT_EVALUATED) +#endif + #if TEST_STD_VER >= 14 # define TEST_CONSTEXPR_CXX14 constexpr #else