Skip to content

[libc++] [test] Fix MSVC warnings #93257

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 7 commits into from
May 28, 2024
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 @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
3 changes: 3 additions & 0 deletions libcxx/test/std/atomics/atomics.ref/wait.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,16 @@ 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)
const bool is_newlib = true;
#else
const bool is_newlib = false;
#endif
(void)is_newlib;
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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,16 @@ 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)
const bool is_newlib = true;
#else
const bool is_newlib = false;
#endif
(void)is_newlib;
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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down
1 change: 0 additions & 1 deletion libcxx/test/support/msvc_stdlib_force_include.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down
Loading