-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[libc++][test] Fix simple warnings #74186
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
Conversation
@llvm/pr-subscribers-libcxx Author: Stephan T. Lavavej (StephanTLavavej) ChangesFound while running libc++'s tests with MSVC's STL. This contains 3 small commits to fix simple warnings; I hope that combining them into a single PR makes things easier.
Full diff: https://github.com/llvm/llvm-project/pull/74186.diff 6 Files Affected:
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 ce5cf0560fc81ae..e6019c477f93e27 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,8 +94,13 @@ 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_VER < 23
+ if (!TEST_IS_CONSTANT_EVALUATED)
+#endif
+ {
types::for_each(types::cpp17_input_iterator_list<std::unique_ptr<int>*>(), Test1OutIters());
+ }
{ // Make sure that padding bits aren't copied
Derived src(1, 2, 3);
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 2ed4d37b9dbe645..dcee48244288bfe 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,8 +92,13 @@ 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_VER < 23
+ if (!TEST_IS_CONSTANT_EVALUATED)
+#endif
+ {
types::for_each(types::bidirectional_iterator_list<std::unique_ptr<int>*>(), Test1OutIters());
+ }
{ // Make sure that padding bits aren't copied
Derived src(1, 2, 3);
diff --git a/libcxx/test/std/containers/views/mdspan/ConvertibleToIntegral.h b/libcxx/test/std/containers/views/mdspan/ConvertibleToIntegral.h
index 470f5d8e724648c..0ca5c330a390e4b 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 a2d46ab1b94c7a5..796ab41716dd5f4 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/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 48a96f90254e3e3..f953fa4f8d6df20 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 91320a52b62aea6..6b4da89c4f2d491 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;
}
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
libcxx/test/std/algorithms/alg.modifying.operations/alg.move/move.pass.cpp
Outdated
Show resolved
Hide resolved
This comment was marked as resolved.
This comment was marked as resolved.
Also apply clang-format from CI.
Examples: libcxx\test\std\containers\views\mdspan\layout_stride\../ConvertibleToIntegral.h(19): warning C4242: 'return': conversion from 'const int' to 'unsigned char', possible loss of data libcxx\test\std\containers\views\mdspan\layout_stride\../ConvertibleToIntegral.h(20): warning C4242: 'return': conversion from 'const int' to 'signed char', possible loss of data libcxx\test\std\containers\views\mdspan\layout_stride\../ConvertibleToIntegral.h(32): warning C4242: 'return': conversion from 'int' to 'char', possible loss of data
b69cfb3
to
9fa9e1b
Compare
Ok, I've got an even simpler approach that should work. The history of reverts and reworks was getting too complicated, so I tidied it up, rebased, and force-pushed. Apologies if this complicates incremental reviewing (I think it should hopefully be easier to follow). Also updated the PR description. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a huge fan of the new macros because they won't compose super well, but it'll do. Thanks for the fix!
Found while running libc++'s tests with MSVC's STL.
This contains 3 commits to fix simple warnings, and 1 cleanup commit.
-Wunused-variable
warnings.ConvertibleToIntegral.h
.static_cast
without worrying about disrupting any usage. Examples:TEST_STD_AT_LEAST_23_OR_RUNTIME_EVALUATED
to avoid mixing preprocessor and runtime tests.if (TEST_STD_VER >= 23 || !TEST_IS_CONSTANT_EVALUATED)
it emitswarning C4127: conditional expression is constant
because the first part is truly a compile-time constant. To fix this, I'm mechanically simplifying it into a centralized macro.TEST_STD_AT_LEAST_20_OR_RUNTIME_EVALUATED
for consistency.