[libcxx-commits] [libcxx] 164c204 - [libc++][test] Fix simple warnings (#74186)
via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Dec 5 06:46:45 PST 2023
Author: Stephan T. Lavavej
Date: 2023-12-05T09:46:41-05:00
New Revision: 164c204a19f7859d570003d4c5e82faf48cb65a9
URL: https://github.com/llvm/llvm-project/commit/164c204a19f7859d570003d4c5e82faf48cb65a9
DIFF: https://github.com/llvm/llvm-project/commit/164c204a19f7859d570003d4c5e82faf48cb65a9.diff
LOG: [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.
Added:
Modified:
libcxx/test/std/algorithms/alg.modifying.operations/alg.move/move.pass.cpp
libcxx/test/std/algorithms/alg.modifying.operations/alg.move/move_backward.pass.cpp
libcxx/test/std/algorithms/alg.nonmodifying/alg.count/count.pass.cpp
libcxx/test/std/containers/views/mdspan/ConvertibleToIntegral.h
libcxx/test/std/numerics/rand/rand.device/ctor.pass.cpp
libcxx/test/std/strings/string.view/string.view.comparison/equal.pass.cpp
libcxx/test/std/strings/string.view/string.view.comparison/greater.pass.cpp
libcxx/test/std/strings/string.view/string.view.comparison/greater_equal.pass.cpp
libcxx/test/std/strings/string.view/string.view.comparison/less.pass.cpp
libcxx/test/std/strings/string.view/string.view.comparison/less_equal.pass.cpp
libcxx/test/std/strings/string.view/string.view.comparison/not_equal.pass.cpp
libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.scoped/mutex.pass.cpp
libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/default.pass.cpp
libcxx/test/support/test_macros.h
Removed:
################################################################################
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 ce5cf0560fc81..b1ad6873bc5e5 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<int*>(), 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<std::unique_ptr<int>*>(), 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 2ed4d37b9dbe6..61dea47b51071 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<int*>(), 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<std::unique_ptr<int>*>(), 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 cc832febdba75..904100c1cf0bb 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<const int*>(), Test());
- if (!TEST_IS_CONSTANT_EVALUATED || TEST_STD_VER >= 20) {
+ if (TEST_STD_AT_LEAST_20_OR_RUNTIME_EVALUATED) {
std::vector<bool> vec(256 + 64);
for (ptr
diff _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 470f5d8e72464..0ca5c330a390e 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<unsigned char>(val); }
+ constexpr operator signed char() const noexcept { return static_cast<signed char>(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<unsigned>(val); }
+ constexpr operator char() noexcept { return static_cast<char>(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 a2d46ab1b94c7..796ab41716dd5 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 4f00bd7f6edf1..fc99df4072131 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<SV>(v[i]) == v[j]) == expected);
assert((v[i] == ConvertibleTo<SV>(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<CharT, Traits>(v[i]) == v[j]) == expected);
assert((v[i] == std::basic_string<CharT, Traits>(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<CharT, Traits>(abc) == abc0def) == false);
assert((abc0def == std::basic_string<CharT, Traits>(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 b965c155ec51b..fd3a438167994 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<SV>(v[i]) > v[j]) == expected);
assert((v[i] > ConvertibleTo<SV>(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<CharT, Traits>(v[i]) > v[j]) == expected);
assert((v[i] > std::basic_string<CharT, Traits>(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<CharT, Traits>(abc) > abc0def) == false);
assert((abc0def > std::basic_string<CharT, Traits>(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 435e7db773199..0d9081e1c01d8 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<SV>(v[i]) >= v[j]) == expected);
assert((v[i] >= ConvertibleTo<SV>(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<CharT, Traits>(v[i]) >= v[j]) == expected);
assert((v[i] >= std::basic_string<CharT, Traits>(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<CharT, Traits>(abc) >= abc0def) == false);
assert((abc0def >= std::basic_string<CharT, Traits>(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 7461b05ce3085..bb61b1df193e6 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<SV>(v[i]) < v[j]) == expected);
assert((v[i] < ConvertibleTo<SV>(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<CharT, Traits>(v[i]) < v[j]) == expected);
assert((v[i] < std::basic_string<CharT, Traits>(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<CharT, Traits>(abc) < abc0def) == true);
assert((abc0def < std::basic_string<CharT, Traits>(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 3192db0dc7d7d..d91e112d6dabf 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<SV>(v[i]) <= v[j]) == expected);
assert((v[i] <= ConvertibleTo<SV>(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<CharT, Traits>(v[i]) <= v[j]) == expected);
assert((v[i] <= std::basic_string<CharT, Traits>(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<CharT, Traits>(abc) <= abc0def) == true);
assert((abc0def <= std::basic_string<CharT, Traits>(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 0082a56839331..a4c8be9f878f0 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<SV>(v[i]) != v[j]) == expected);
assert((v[i] != ConvertibleTo<SV>(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<CharT, Traits>(v[i]) != v[j]) == expected);
assert((v[i] != std::basic_string<CharT, Traits>(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<CharT, Traits>(abc) != abc0def) == true);
assert((abc0def != std::basic_string<CharT, Traits>(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 48a96f90254e3..f953fa4f8d6df 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<TestMutex>;
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 91320a52b62ae..5504645bb31f9 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 f3c6d8080ff6d..02678d987d265 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
More information about the libcxx-commits
mailing list