Author: stl_msft Date: Mon Dec 5 19:13:51 2016 New Revision: 288749 URL: http://llvm.org/viewvc/llvm-project?rev=288749&view=rev Log: [libcxx] [test] D27025: Fix MSVC warning C4389 "signed/unsigned mismatch", part 12/12.
Various changes: test/std/algorithms/alg.sorting/alg.merge/inplace_merge.pass.cpp This is comparing value_type to unsigned. value_type is sometimes int and sometimes struct S (implicitly constructible from int). static_cast<value_type>(unsigned) silences the warning and doesn't do anything bad (as the values in question are small). test/std/algorithms/alg.sorting/alg.nth.element/nth_element_comp.pass.cpp This is comparing an int remote-element to size_t. The values in question are small and non-negative, so either type is fine. I think that converting int to size_t is marginally better here than the reverse. test/std/containers/sequences/deque/deque.cons/size.pass.cpp DefaultOnly::count is int (and non-negative). When comparing to unsigned, use static_cast<unsigned>. test/std/strings/basic.string/string.access/index.pass.cpp We're comparing char to '0' through '9', but formed with the type size_t. Add static_cast<char>. test/std/utilities/template.bitset/bitset.cons/ull_ctor.pass.cpp Include <cstddef> for pedantic correctness (this test was already mentioning std::size_t). "v[i] == (i & 1)" was comparing bool to size_t. Saying "v[i] == ((i & 1) != 0)" smashes the RHS to bool. Modified: libcxx/trunk/test/std/algorithms/alg.sorting/alg.merge/inplace_merge.pass.cpp libcxx/trunk/test/std/algorithms/alg.sorting/alg.nth.element/nth_element_comp.pass.cpp libcxx/trunk/test/std/containers/sequences/deque/deque.cons/size.pass.cpp libcxx/trunk/test/std/strings/basic.string/string.access/index.pass.cpp libcxx/trunk/test/std/utilities/template.bitset/bitset.cons/ull_ctor.pass.cpp Modified: libcxx/trunk/test/std/algorithms/alg.sorting/alg.merge/inplace_merge.pass.cpp URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/algorithms/alg.sorting/alg.merge/inplace_merge.pass.cpp?rev=288749&r1=288748&r2=288749&view=diff ============================================================================== --- libcxx/trunk/test/std/algorithms/alg.sorting/alg.merge/inplace_merge.pass.cpp (original) +++ libcxx/trunk/test/std/algorithms/alg.sorting/alg.merge/inplace_merge.pass.cpp Mon Dec 5 19:13:51 2016 @@ -58,7 +58,7 @@ test_one(unsigned N, unsigned M) if(N > 0) { assert(ia[0] == 0); - assert(ia[N-1] == N-1); + assert(ia[N-1] == static_cast<value_type>(N-1)); assert(std::is_sorted(ia, ia+N)); } delete [] ia; Modified: libcxx/trunk/test/std/algorithms/alg.sorting/alg.nth.element/nth_element_comp.pass.cpp URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/algorithms/alg.sorting/alg.nth.element/nth_element_comp.pass.cpp?rev=288749&r1=288748&r2=288749&view=diff ============================================================================== --- libcxx/trunk/test/std/algorithms/alg.sorting/alg.nth.element/nth_element_comp.pass.cpp (original) +++ libcxx/trunk/test/std/algorithms/alg.sorting/alg.nth.element/nth_element_comp.pass.cpp Mon Dec 5 19:13:51 2016 @@ -81,7 +81,7 @@ int main() for (int i = 0; static_cast<std::size_t>(i) < v.size(); ++i) v[i].reset(new int(i)); std::nth_element(v.begin(), v.begin() + v.size()/2, v.end(), indirect_less()); - assert(*v[v.size()/2] == v.size()/2); + assert(static_cast<std::size_t>(*v[v.size()/2]) == v.size()/2); } #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES } Modified: libcxx/trunk/test/std/containers/sequences/deque/deque.cons/size.pass.cpp URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/sequences/deque/deque.cons/size.pass.cpp?rev=288749&r1=288748&r2=288749&view=diff ============================================================================== --- libcxx/trunk/test/std/containers/sequences/deque/deque.cons/size.pass.cpp (original) +++ libcxx/trunk/test/std/containers/sequences/deque/deque.cons/size.pass.cpp Mon Dec 5 19:13:51 2016 @@ -30,7 +30,7 @@ test2(unsigned n) assert(DefaultOnly::count == 0); { C d(n, Allocator()); - assert(DefaultOnly::count == n); + assert(static_cast<unsigned>(DefaultOnly::count) == n); assert(d.size() == n); assert(static_cast<std::size_t>(distance(d.begin(), d.end())) == d.size()); #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES @@ -51,7 +51,7 @@ test1(unsigned n) assert(DefaultOnly::count == 0); { C d(n); - assert(DefaultOnly::count == n); + assert(static_cast<unsigned>(DefaultOnly::count) == n); assert(d.size() == n); assert(static_cast<std::size_t>(distance(d.begin(), d.end())) == d.size()); #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES Modified: libcxx/trunk/test/std/strings/basic.string/string.access/index.pass.cpp URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.access/index.pass.cpp?rev=288749&r1=288748&r2=288749&view=diff ============================================================================== --- libcxx/trunk/test/std/strings/basic.string/string.access/index.pass.cpp (original) +++ libcxx/trunk/test/std/strings/basic.string/string.access/index.pass.cpp Mon Dec 5 19:13:51 2016 @@ -29,7 +29,7 @@ int main() const S& cs = s; for (S::size_type i = 0; i < cs.size(); ++i) { - assert(s[i] == '0' + i); + assert(s[i] == static_cast<char>('0' + i)); assert(cs[i] == s[i]); } assert(cs[cs.size()] == '\0'); @@ -43,7 +43,7 @@ int main() const S& cs = s; for (S::size_type i = 0; i < cs.size(); ++i) { - assert(s[i] == '0' + i); + assert(s[i] == static_cast<char>('0' + i)); assert(cs[i] == s[i]); } assert(cs[cs.size()] == '\0'); Modified: libcxx/trunk/test/std/utilities/template.bitset/bitset.cons/ull_ctor.pass.cpp URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/template.bitset/bitset.cons/ull_ctor.pass.cpp?rev=288749&r1=288748&r2=288749&view=diff ============================================================================== --- libcxx/trunk/test/std/utilities/template.bitset/bitset.cons/ull_ctor.pass.cpp (original) +++ libcxx/trunk/test/std/utilities/template.bitset/bitset.cons/ull_ctor.pass.cpp Mon Dec 5 19:13:51 2016 @@ -12,6 +12,7 @@ #include <bitset> #include <cassert> #include <algorithm> // for 'min' and 'max' +#include <cstddef> #include "test_macros.h" @@ -23,7 +24,7 @@ void test_val_ctor() assert(v.size() == N); unsigned M = std::min<std::size_t>(N, 64); for (std::size_t i = 0; i < M; ++i) - assert(v[i] == (i & 1)); + assert(v[i] == ((i & 1) != 0)); for (std::size_t i = M; i < N; ++i) assert(v[i] == false); } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits