[libc++][test] Fix more MSVC warnings#74256
Merged
Conversation
…erator::operator ->' is recursive if applied using infix notation".
…4' to 'unsigned int', possible loss of data". An allocator's deallocate() should be able to take its size type.
Member
|
@llvm/pr-subscribers-libcxx Author: Stephan T. Lavavej (StephanTLavavej) ChangesFound while running libc++'s test suite with MSVC's STL.
Full diff: https://github.com/llvm/llvm-project/pull/74256.diff 4 Files Affected:
diff --git a/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.assign/member_swap_noexcept.pass.cpp b/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.assign/member_swap_noexcept.pass.cpp
index cdb09df7c7a9a..0a0128e44658f 100644
--- a/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.assign/member_swap_noexcept.pass.cpp
+++ b/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.assign/member_swap_noexcept.pass.cpp
@@ -27,7 +27,7 @@ struct test_alloc {
using value_type = T;
[[nodiscard]] constexpr T* allocate(std::size_t) { return nullptr; }
- void deallocate(void*, unsigned) {}
+ void deallocate(void*, std::size_t) {}
};
template <class T>
diff --git a/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.assign/nonmember_swap_noexcept.pass.cpp b/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.assign/nonmember_swap_noexcept.pass.cpp
index fdefc5ebe9af0..4f41e3a4d716a 100644
--- a/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.assign/nonmember_swap_noexcept.pass.cpp
+++ b/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.assign/nonmember_swap_noexcept.pass.cpp
@@ -26,7 +26,7 @@ struct test_alloc {
using value_type = T;
[[nodiscard]] constexpr T* allocate(std::size_t) { return nullptr; }
- void deallocate(void*, unsigned) {}
+ void deallocate(void*, std::size_t) {}
};
template <class T>
diff --git a/libcxx/test/std/ranges/range.adaptors/range.filter/iterator/arrow.pass.cpp b/libcxx/test/std/ranges/range.adaptors/range.filter/iterator/arrow.pass.cpp
index f139226b875f0..0c02cfdb76ad3 100644
--- a/libcxx/test/std/ranges/range.adaptors/range.filter/iterator/arrow.pass.cpp
+++ b/libcxx/test/std/ranges/range.adaptors/range.filter/iterator/arrow.pass.cpp
@@ -59,7 +59,7 @@ struct WithNonCopyableIterator : std::ranges::view_base {
iterator(iterator&&);
iterator& operator=(iterator&&);
XYPoint& operator*() const;
- iterator operator->() const;
+ XYPoint* operator->() const;
iterator& operator++();
iterator operator++(int);
diff --git a/libcxx/test/std/ranges/range.factories/range.repeat.view/size.pass.cpp b/libcxx/test/std/ranges/range.factories/range.repeat.view/size.pass.cpp
index 72531b059aa24..6f24b3b9bf75a 100644
--- a/libcxx/test/std/ranges/range.factories/range.repeat.view/size.pass.cpp
+++ b/libcxx/test/std/ranges/range.factories/range.repeat.view/size.pass.cpp
@@ -31,8 +31,9 @@ constexpr bool test() {
}
{
- std::ranges::repeat_view<int, int> rv(10, std::numeric_limits<int>::max());
- assert(rv.size() == std::numeric_limits<int>::max());
+ constexpr int int_max = std::numeric_limits<int>::max();
+ std::ranges::repeat_view<int, int> rv(10, int_max);
+ assert(rv.size() == int_max);
}
return true;
|
ldionne
approved these changes
Dec 6, 2023
This file contains hidden or 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
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 test suite with MSVC's STL.
WithNonCopyableIterator::iterator::operator ->' is recursive if applied using infix notation".XYPoint*, likeWithArrowOperatorimmediately above, fixes the warning.==': signed/unsigned mismatch".repeat_view'ssize()being compared with theintreturn value of a function, and a negative value would undergo a value-modifying conversion, so it warns. This happens because MSVC is exceptionally lazy aboutconstexprfunction calls, so it's callingstd::numeric_limits<int>::max()at runtime and doesn't realize that it's a positive constant. By extracting this into aconstexprvariable, MSVC is satisfied thatint_maxwill undergo a value-preserving conversion. This costs an extra line but slightly reduces the repetition ofstd::numeric_limits<int>::max()so I hope it's acceptable.unsigned __int64' to 'unsigned int', possible loss of data".deallocate()should be able to take its size type. In these tests, MSVC is instantiating enough of the allocator machinery to emit this warning. These test allocators weren't intentionally trying to makedeallocate()have a weird parameter type - these tests are interested in POCS etc. and theallocate()/deallocate()are just stubs.