-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
[libc++] [test] Fix MSVC warnings #93257
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…ike macro argument list is undefined behavior. Followup to LLVM-73440. See LLVM-73598 and LLVM-73836.
…, possible loss of data.
…pe, result still unsigned.
These warnings are being emitted by `T(255)`. Followup to LLVM-79791.
…ied'. Since at least MSVC-PR-368907 on 2021-12-09.
@llvm/pr-subscribers-libcxx Author: Stephan T. Lavavej (StephanTLavavej) ChangesFound while running libc++'s tests with MSVC's STL.
Full diff: https://github.com/llvm/llvm-project/pull/93257.diff 8 Files Affected:
diff --git a/libcxx/test/std/atomics/atomics.ref/compare_exchange_strong.pass.cpp b/libcxx/test/std/atomics/atomics.ref/compare_exchange_strong.pass.cpp
index 72b2f444c476c..90aa5ea5b6df4 100644
--- a/libcxx/test/std/atomics/atomics.ref/compare_exchange_strong.pass.cpp
+++ b/libcxx/test/std/atomics/atomics.ref/compare_exchange_strong.pass.cpp
@@ -9,6 +9,9 @@
// XFAIL: !has-64-bit-atomics
// XFAIL: !has-1024-bit-atomics
+// MSVC warning C4310: cast truncates constant value
+// ADDITIONAL_COMPILE_FLAGS(cl-style-warnings): /wd4310
+
// bool compare_exchange_strong(T&, T, memory_order, memory_order) const noexcept;
// bool compare_exchange_strong(T&, T, memory_order = memory_order::seq_cst) const noexcept;
diff --git a/libcxx/test/std/atomics/atomics.ref/compare_exchange_weak.pass.cpp b/libcxx/test/std/atomics/atomics.ref/compare_exchange_weak.pass.cpp
index 5219a8e3714f9..99c1385a2fe0b 100644
--- a/libcxx/test/std/atomics/atomics.ref/compare_exchange_weak.pass.cpp
+++ b/libcxx/test/std/atomics/atomics.ref/compare_exchange_weak.pass.cpp
@@ -9,6 +9,9 @@
// XFAIL: !has-64-bit-atomics
// XFAIL: !has-1024-bit-atomics
+// MSVC warning C4310: cast truncates constant value
+// ADDITIONAL_COMPILE_FLAGS(cl-style-warnings): /wd4310
+
// bool compare_exchange_weak(T&, T, memory_order, memory_order) const noexcept;
// bool compare_exchange_weak(T&, T, memory_order = memory_order::seq_cst) const noexcept;
diff --git a/libcxx/test/std/atomics/atomics.ref/wait.pass.cpp b/libcxx/test/std/atomics/atomics.ref/wait.pass.cpp
index e5310febf5c5e..f246803ba2592 100644
--- a/libcxx/test/std/atomics/atomics.ref/wait.pass.cpp
+++ b/libcxx/test/std/atomics/atomics.ref/wait.pass.cpp
@@ -11,6 +11,9 @@
// XFAIL: !has-64-bit-atomics
// XFAIL: !has-1024-bit-atomics
+// MSVC warning C4310: cast truncates constant value
+// ADDITIONAL_COMPILE_FLAGS(cl-style-warnings): /wd4310
+
// void wait(T, memory_order = memory_order::seq_cst) const noexcept;
#include <atomic>
diff --git a/libcxx/test/std/containers/views/views.span/span.cons/initializer_list.pass.cpp b/libcxx/test/std/containers/views/views.span/span.cons/initializer_list.pass.cpp
index 74a5094f61261..bc76e23fea3c0 100644
--- a/libcxx/test/std/containers/views/views.span/span.cons/initializer_list.pass.cpp
+++ b/libcxx/test/std/containers/views/views.span/span.cons/initializer_list.pass.cpp
@@ -93,9 +93,9 @@ constexpr bool test() {
// Test P2447R4 "Annex C examples"
-constexpr int three(std::span<void* const> sp) { return sp.size(); }
+constexpr int three(std::span<void* const> sp) { return static_cast<int>(sp.size()); }
-constexpr int four(std::span<const std::any> sp) { return sp.size(); }
+constexpr int four(std::span<const std::any> sp) { return static_cast<int>(sp.size()); }
bool test_P2447R4_annex_c_examples() {
// 1. Overload resolution is affected
diff --git a/libcxx/test/std/diagnostics/syserr/syserr.errcat/syserr.errcat.objects/generic_category.pass.cpp b/libcxx/test/std/diagnostics/syserr/syserr.errcat/syserr.errcat.objects/generic_category.pass.cpp
index d4bbde75ae882..f9e49d02b8860 100644
--- a/libcxx/test/std/diagnostics/syserr/syserr.errcat/syserr.errcat.objects/generic_category.pass.cpp
+++ b/libcxx/test/std/diagnostics/syserr/syserr.errcat/syserr.errcat.objects/generic_category.pass.cpp
@@ -50,12 +50,15 @@ int main(int, char**)
// responds with an empty message, which we probably want to
// treat as a failure code otherwise, but we can detect that
// with the preprocessor.
+#if defined(_NEWLIB_VERSION)
+ [[maybe_unused]] constexpr bool is_newlib = true;
+#else
+ [[maybe_unused]] constexpr bool is_newlib = false;
+#endif
LIBCPP_ASSERT(msg.rfind("Error -1 occurred", 0) == 0 // AIX
|| msg.rfind("No error information", 0) == 0 // Musl
|| msg.rfind("Unknown error", 0) == 0 // Glibc
-#if defined(_NEWLIB_VERSION)
- || msg.empty()
-#endif
+ || (is_newlib && msg.empty())
);
assert(errno == E2BIG);
}
diff --git a/libcxx/test/std/diagnostics/syserr/syserr.errcat/syserr.errcat.objects/system_category.pass.cpp b/libcxx/test/std/diagnostics/syserr/syserr.errcat/syserr.errcat.objects/system_category.pass.cpp
index eefbddd27a7f5..a14d6cd6cb4fb 100644
--- a/libcxx/test/std/diagnostics/syserr/syserr.errcat/syserr.errcat.objects/system_category.pass.cpp
+++ b/libcxx/test/std/diagnostics/syserr/syserr.errcat/syserr.errcat.objects/system_category.pass.cpp
@@ -56,12 +56,15 @@ int main(int, char**) {
// responds with an empty message, which we probably want to
// treat as a failure code otherwise, but we can detect that
// with the preprocessor.
+#if defined(_NEWLIB_VERSION)
+ [[maybe_unused]] constexpr bool is_newlib = true;
+#else
+ [[maybe_unused]] constexpr bool is_newlib = false;
+#endif
LIBCPP_ASSERT(msg.rfind("Error -1 occurred", 0) == 0 // AIX
|| msg.rfind("No error information", 0) == 0 // Musl
|| msg.rfind("Unknown error", 0) == 0 // Glibc
-#if defined(_NEWLIB_VERSION)
- || msg.empty()
-#endif
+ || (is_newlib && msg.empty())
);
assert(errno == E2BIG);
}
diff --git a/libcxx/test/std/numerics/numeric.ops/numeric.ops.gcd/gcd.pass.cpp b/libcxx/test/std/numerics/numeric.ops/numeric.ops.gcd/gcd.pass.cpp
index 212804356a056..bf40b174b209c 100644
--- a/libcxx/test/std/numerics/numeric.ops/numeric.ops.gcd/gcd.pass.cpp
+++ b/libcxx/test/std/numerics/numeric.ops/numeric.ops.gcd/gcd.pass.cpp
@@ -57,10 +57,12 @@ T basic_gcd_(T m, T n) {
template <typename T>
T basic_gcd(T m, T n) {
using Tp = std::make_unsigned_t<T>;
- if (m < 0 && m != std::numeric_limits<T>::min())
- m = -m;
- if (n < 0 && n != std::numeric_limits<T>::min())
- n = -n;
+ if constexpr (std::is_signed_v<T>) {
+ if (m < 0 && m != std::numeric_limits<T>::min())
+ m = -m;
+ if (n < 0 && n != std::numeric_limits<T>::min())
+ n = -n;
+ }
return basic_gcd_(static_cast<Tp>(m), static_cast<Tp>(n));
}
diff --git a/libcxx/test/support/msvc_stdlib_force_include.h b/libcxx/test/support/msvc_stdlib_force_include.h
index 6c26085e72c45..35783c1607b0e 100644
--- a/libcxx/test/support/msvc_stdlib_force_include.h
+++ b/libcxx/test/support/msvc_stdlib_force_include.h
@@ -67,7 +67,6 @@ const AssertionDialogAvoider assertion_dialog_avoider{};
// Silence compiler warnings.
# pragma warning(disable : 4180) // qualifier applied to function type has no meaning; ignored
# pragma warning(disable : 4324) // structure was padded due to alignment specifier
-# pragma warning(disable : 4521) // multiple copy constructors specified
# pragma warning(disable : 4702) // unreachable code
# pragma warning(disable : 28251) // Inconsistent annotation for 'new': this instance has no annotations.
#endif // !defined(__clang__)
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
cjdb
approved these changes
May 28, 2024
ldionne
approved these changes
May 28, 2024
vg0204
pushed a commit
to vg0204/llvm-project
that referenced
this pull request
May 29, 2024
Found while running libc++'s tests with MSVC's STL. * Avoid MSVC warning C5101: use of preprocessor directive in function-like macro argument list is undefined behavior. + We can easily make this portable by extracting `const bool is_newlib`. + Followup to llvm#73440. + See llvm#73598. + See llvm#73836. * Avoid MSVC warning C4267: 'return': conversion from 'size_t' to 'int', possible loss of data. + This warning is valid, but harmless for the test, so `static_cast<int>` will avoid it. * Avoid MSVC warning C4146: unary minus operator applied to unsigned type, result still unsigned. + This warning is also valid (the scenario is sometimes intentional, but surprising enough that it's worth warning about). This is a C++17 test, so we can easily avoid it by testing `is_signed_v` at compile-time before testing `m < 0` and `n < 0` at run-time. * Silence MSVC warning C4310: cast truncates constant value. + These warnings are being emitted by `T(255)`. Disabling the warning is simpler than attempting to restructure the code. + Followup to llvm#79791. * MSVC no longer emits warning C4521: multiple copy constructors specified. + This warning was removed from the compiler, since at least 2021-12-09.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Found while running libc++'s tests with MSVC's STL.
const bool is_newlib
.static_cast<int>
will avoid it.is_signed_v
at compile-time before testingm < 0
andn < 0
at run-time.T(255)
. Disabling the warning is simpler than attempting to restructure the code.