Skip to content

[libc++][test] Silence MSVC warnings#79791

Merged
philnik777 merged 3 commits intollvm:mainfrom
StephanTLavavej:silence-mortals
Jan 29, 2024
Merged

[libc++][test] Silence MSVC warnings#79791
philnik777 merged 3 commits intollvm:mainfrom
StephanTLavavej:silence-mortals

Conversation

@StephanTLavavej
Copy link
Member

  • libcxx/test/std/algorithms/alg.nonmodifying/alg.find/find.pass.cpp emits a bunch of warnings, all caused by what appears to be intentional code:
    • Silence MSVC warning C4245: conversion from 'int' to 'wchar_t', signed/unsigned mismatch
      • Caused by: test<U>(0, -1);
    • Silence MSVC warning C4305: 'argument': truncation from 'int' to 'bool'
      • Caused by: test<U>(0, -1);
    • Silence MSVC warning C4310: cast truncates constant value
      • Caused by: test<U>(T(-129), U(-129));
    • Silence MSVC warning C4805: '==': unsafe mix of type 'char' and type 'bool' in operation
      • Caused by: bool expect_match = val == to_find;
  • libcxx/test/std/algorithms/alg.nonmodifying/alg.fold/left_folds.pass.cpp
    • Silence MSVC warning C4244: 'argument': conversion from 'double' to 'const int', possible loss of data
      • Caused by [](int const x, double const y) { return x + y; } deliberately being given doubles to truncate.
  • libcxx/test/std/numerics/numeric.ops/numeric.ops.midpoint/midpoint.pointer.pass.cpp
    • Silence MSVC warnings about C++20 deprecated volatile.
      • Caused by: runtime_test< volatile T>();

* Silence MSVC warning C4245: conversion from 'int' to 'wchar_t', signed/unsigned mismatch
  + Caused by: `test<U>(0, -1);`
* Silence MSVC warning C4305: 'argument': truncation from 'int' to 'bool'
  + Caused by: `test<U>(0, -1);`
* Silence MSVC warning C4310: cast truncates constant value
  + Caused by: `test<U>(T(-129), U(-129));`
* Silence MSVC warning C4805: '==': unsafe mix of type 'char' and type 'bool' in operation
  + Caused by: `bool expect_match = val == to_find;`
Caused by: `runtime_test<      volatile T>();`
…const int', possible loss of data

Caused by `[](int const x, double const y) { return x + y; }` deliberately being given doubles to truncate.
@StephanTLavavej StephanTLavavej requested a review from a team as a code owner January 29, 2024 07:14
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Jan 29, 2024
@llvmbot
Copy link
Member

llvmbot commented Jan 29, 2024

@llvm/pr-subscribers-libcxx

Author: Stephan T. Lavavej (StephanTLavavej)

Changes
  • libcxx/test/std/algorithms/alg.nonmodifying/alg.find/find.pass.cpp emits a bunch of warnings, all caused by what appears to be intentional code:
    • Silence MSVC warning C4245: conversion from 'int' to 'wchar_t', signed/unsigned mismatch
      • Caused by: test&lt;U&gt;(0, -1);
    • Silence MSVC warning C4305: 'argument': truncation from 'int' to 'bool'
      • Caused by: test&lt;U&gt;(0, -1);
    • Silence MSVC warning C4310: cast truncates constant value
      • Caused by: test&lt;U&gt;(T(-129), U(-129));
    • Silence MSVC warning C4805: '==': unsafe mix of type 'char' and type 'bool' in operation
      • Caused by: bool expect_match = val == to_find;
  • libcxx/test/std/algorithms/alg.nonmodifying/alg.fold/left_folds.pass.cpp
    • Silence MSVC warning C4244: 'argument': conversion from 'double' to 'const int', possible loss of data
      • Caused by [](int const x, double const y) { return x + y; } deliberately being given doubles to truncate.
  • libcxx/test/std/numerics/numeric.ops/numeric.ops.midpoint/midpoint.pointer.pass.cpp
    • Silence MSVC warnings about C++20 deprecated volatile.
      • Caused by: runtime_test&lt; volatile T&gt;();

Full diff: https://github.com/llvm/llvm-project/pull/79791.diff

3 Files Affected:

  • (modified) libcxx/test/std/algorithms/alg.nonmodifying/alg.find/find.pass.cpp (+5-1)
  • (modified) libcxx/test/std/algorithms/alg.nonmodifying/alg.fold/left_folds.pass.cpp (+3)
  • (modified) libcxx/test/std/numerics/numeric.ops/numeric.ops.midpoint/midpoint.pointer.pass.cpp (+5)
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.find/find.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.find/find.pass.cpp
index 0676da13e90f76b..c41246522fdebac 100644
--- a/libcxx/test/std/algorithms/alg.nonmodifying/alg.find/find.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.find/find.pass.cpp
@@ -8,8 +8,12 @@
 
 // ADDITIONAL_COMPILE_FLAGS(gcc): -Wno-bool-compare
 // ADDITIONAL_COMPILE_FLAGS(gcc-style-warnings): -Wno-sign-compare
+// MSVC warning C4245: conversion from 'int' to 'wchar_t', signed/unsigned mismatch
+// MSVC warning C4305: truncation from 'int' to 'bool'
+// MSVC warning C4310: cast truncates constant value
 // MSVC warning C4389: '==': signed/unsigned mismatch
-// ADDITIONAL_COMPILE_FLAGS(cl-style-warnings): /wd4389
+// MSVC warning C4805: '==': unsafe mix of type 'char' and type 'bool' in operation
+// ADDITIONAL_COMPILE_FLAGS(cl-style-warnings): /wd4245 /wd4305 /wd4310 /wd4389 /wd4805
 
 // <algorithm>
 
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.fold/left_folds.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.fold/left_folds.pass.cpp
index cf089b27c76e029..b8da26a229fa995 100644
--- a/libcxx/test/std/algorithms/alg.nonmodifying/alg.fold/left_folds.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.fold/left_folds.pass.cpp
@@ -10,6 +10,9 @@
 
 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
 
+// MSVC warning C4244: 'argument': conversion from 'double' to 'const int', possible loss of data
+// ADDITIONAL_COMPILE_FLAGS(cl-style-warnings): /wd4244
+
 // template<input_iterator I, sentinel_for<I> S, class T,
 //          indirectly-binary-left-foldable<T, I> F>
 //   constexpr see below ranges::fold_left_with_iter(I first, S last, T init, F f);
diff --git a/libcxx/test/std/numerics/numeric.ops/numeric.ops.midpoint/midpoint.pointer.pass.cpp b/libcxx/test/std/numerics/numeric.ops/numeric.ops.midpoint/midpoint.pointer.pass.cpp
index 5138fd6a37469f7..e8a25c174076a62 100644
--- a/libcxx/test/std/numerics/numeric.ops/numeric.ops.midpoint/midpoint.pointer.pass.cpp
+++ b/libcxx/test/std/numerics/numeric.ops/numeric.ops.midpoint/midpoint.pointer.pass.cpp
@@ -7,6 +7,11 @@
 //===----------------------------------------------------------------------===//
 //
 // UNSUPPORTED: c++03, c++11, c++14, c++17
+
+// MSVC warning C5215: a function parameter with a volatile qualified type is deprecated in C++20
+// MSVC warning C5216: a volatile qualified return type is deprecated in C++20
+// ADDITIONAL_COMPILE_FLAGS(cl-style-warnings): /wd5215 /wd5216
+
 // <numeric>
 
 // template <class _Tp>

@philnik777 philnik777 merged commit c9535d7 into llvm:main Jan 29, 2024
@StephanTLavavej StephanTLavavej deleted the silence-mortals branch January 29, 2024 11:03
ldionne pushed a commit that referenced this pull request May 28, 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 #73440.
  + See #73598.
  + See #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 #79791.
* MSVC no longer emits warning C4521: multiple copy constructors
specified.
+ This warning was removed from the compiler, since at least 2021-12-09.
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

Labels

libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants