[libcxx] [test] D27022: Fix MSVC warning C4389 "signed/unsigned mismatch", part 9/12.

Add static_cast<std::size_t> to more comparisons. (Performed manually, unlike part 8/12.)

Also, include <cstddef> when it wasn't already being included.

llvm-svn: 288746
This commit is contained in:
Stephan T. Lavavej 2016-12-06 01:13:14 +00:00
parent fbfb2ab63e
commit 68a694b800
23 changed files with 69 additions and 49 deletions

View File

@ -21,6 +21,7 @@
#include <random>
#include <type_traits>
#include <cassert>
#include <cstddef>
#include "test_iterators.h"
#include "test_macros.h"
@ -70,14 +71,14 @@ void test() {
end = std::sample(PopulationIterator(ia),
PopulationIterator(ia + is),
SampleIterator(oa), os, g);
assert(end.base() - oa == std::min(os, is));
assert(static_cast<std::size_t>(end.base() - oa) == std::min(os, is));
// sample() is deterministic but non-reproducible;
// its results can vary between implementations.
LIBCPP_ASSERT(std::equal(oa, oa + os, oa1));
end = std::sample(PopulationIterator(ia),
PopulationIterator(ia + is),
SampleIterator(oa), os, std::move(g));
assert(end.base() - oa == std::min(os, is));
assert(static_cast<std::size_t>(end.base() - oa) == std::min(os, is));
LIBCPP_ASSERT(std::equal(oa, oa + os, oa2));
}
@ -127,7 +128,7 @@ void test_small_population() {
end = std::sample(PopulationIterator(ia),
PopulationIterator(ia + is),
SampleIterator(oa), os, g);
assert(end.base() - oa == std::min(os, is));
assert(static_cast<std::size_t>(end.base() - oa) == std::min(os, is));
typedef typename std::iterator_traits<PopulationIterator>::iterator_category PopulationCategory;
if (std::is_base_of<std::forward_iterator_tag, PopulationCategory>::value) {
assert(std::equal(oa, end.base(), oa1));

View File

@ -14,12 +14,13 @@
#include <queue>
#include <cassert>
#include <cstddef>
int main()
{
int a[] = {3, 5, 2, 0, 6, 8, 1};
int* an = a + sizeof(a)/sizeof(a[0]);
std::priority_queue<int> q(a, an);
assert(q.size() == an - a);
assert(q.size() == static_cast<std::size_t>(an - a));
assert(q.top() == 8);
}

View File

@ -15,6 +15,7 @@
#include <queue>
#include <cassert>
#include <functional>
#include <cstddef>
int main()
{
@ -22,6 +23,6 @@ int main()
int* an = a + sizeof(a)/sizeof(a[0]);
std::priority_queue<int, std::vector<int>, std::greater<int> >
q(a, an, std::greater<int>());
assert(q.size() == an - a);
assert(q.size() == static_cast<std::size_t>(an - a));
assert(q.top() == 0);
}

View File

@ -49,7 +49,7 @@ test(C& c1, int size)
typedef typename C::const_iterator CI;
typename C::size_type c1_osize = c1.size();
c1.resize(size);
assert(c1.size() == size);
assert(c1.size() == static_cast<std::size_t>(size));
assert(static_cast<std::size_t>(distance(c1.begin(), c1.end())) == c1.size());
CI i = c1.begin();
for (int j = 0; static_cast<std::size_t>(j) < std::min(c1_osize, c1.size()); ++j, ++i)

View File

@ -49,7 +49,7 @@ test(C& c1, int size, int x)
typedef typename C::const_iterator CI;
typename C::size_type c1_osize = c1.size();
c1.resize(size, x);
assert(c1.size() == size);
assert(c1.size() == static_cast<std::size_t>(size));
assert(static_cast<std::size_t>(distance(c1.begin(), c1.end())) == c1.size());
CI i = c1.begin();
for (int j = 0; static_cast<std::size_t>(j) < std::min(c1_osize, c1.size()); ++j, ++i)

View File

@ -47,7 +47,7 @@ test(C& c1, int size, int v)
{
typedef typename C::const_iterator CI;
c1.assign(size, v);
assert(c1.size() == size);
assert(c1.size() == static_cast<std::size_t>(size));
assert(static_cast<std::size_t>(distance(c1.begin(), c1.end())) == c1.size());
for (CI i = c1.begin(); i != c1.end(); ++i)
assert(*i == v);

View File

@ -14,6 +14,7 @@
#include <forward_list>
#include <cassert>
#include <cstddef>
#include "test_macros.h"
#include "DefaultOnly.h"
@ -26,7 +27,7 @@ void check_allocator(unsigned n, Allocator const &alloc = Allocator())
typedef std::forward_list<T, Allocator> C;
C d(n, alloc);
assert(d.get_allocator() == alloc);
assert(std::distance(d.begin(), d.end()) == n);
assert(static_cast<std::size_t>(std::distance(d.begin(), d.end())) == n);
#endif
}

View File

@ -14,6 +14,7 @@
#include <forward_list>
#include <iterator>
#include <cassert>
#include <cstddef>
#include "min_allocator.h"
#include "counting_predicates.hpp"
@ -37,7 +38,7 @@ int main()
Predicate cp(g);
c1.remove_if(std::ref(cp));
assert(c1 == c2);
assert(cp.count() == std::distance(std::begin(t1), std::end(t1)));
assert(cp.count() == static_cast<std::size_t>(std::distance(std::begin(t1), std::end(t1))));
}
{
typedef int T;
@ -49,7 +50,7 @@ int main()
Predicate cp(g);
c1.remove_if(std::ref(cp));
assert(c1 == c2);
assert(cp.count() == std::distance(std::begin(t1), std::end(t1)));
assert(cp.count() == static_cast<std::size_t>(std::distance(std::begin(t1), std::end(t1))));
}
{
typedef int T;
@ -62,7 +63,7 @@ int main()
Predicate cp(g);
c1.remove_if(std::ref(cp));
assert(c1 == c2);
assert(cp.count() == std::distance(std::begin(t1), std::end(t1)));
assert(cp.count() == static_cast<std::size_t>(std::distance(std::begin(t1), std::end(t1))));
}
{
typedef int T;
@ -86,7 +87,7 @@ int main()
Predicate cp(g);
c1.remove_if(std::ref(cp));
assert(c1 == c2);
assert(cp.count() == std::distance(std::begin(t1), std::end(t1)));
assert(cp.count() == static_cast<std::size_t>(std::distance(std::begin(t1), std::end(t1))));
}
#if TEST_STD_VER >= 11
{
@ -100,7 +101,7 @@ int main()
Predicate cp(g);
c1.remove_if(std::ref(cp));
assert(c1 == c2);
assert(cp.count() == std::distance(std::begin(t1), std::end(t1)));
assert(cp.count() == static_cast<std::size_t>(std::distance(std::begin(t1), std::end(t1))));
}
{
typedef int T;
@ -112,7 +113,7 @@ int main()
Predicate cp(g);
c1.remove_if(std::ref(cp));
assert(c1 == c2);
assert(cp.count() == std::distance(std::begin(t1), std::end(t1)));
assert(cp.count() == static_cast<std::size_t>(std::distance(std::begin(t1), std::end(t1))));
}
{
typedef int T;
@ -125,7 +126,7 @@ int main()
Predicate cp(g);
c1.remove_if(std::ref(cp));
assert(c1 == c2);
assert(cp.count() == std::distance(std::begin(t1), std::end(t1)));
assert(cp.count() == static_cast<std::size_t>(std::distance(std::begin(t1), std::end(t1))));
}
{
typedef int T;
@ -149,7 +150,7 @@ int main()
Predicate cp(g);
c1.remove_if(std::ref(cp));
assert(c1 == c2);
assert(cp.count() == std::distance(std::begin(t1), std::end(t1)));
assert(cp.count() == static_cast<std::size_t>(std::distance(std::begin(t1), std::end(t1))));
}
#endif
}

View File

@ -13,6 +13,7 @@
#include <list>
#include <cassert>
#include <cstddef>
#include "test_macros.h"
#include "DefaultOnly.h"
#include "test_allocator.h"
@ -28,7 +29,7 @@ test3(unsigned n, Allocator const &alloc = Allocator())
{
C d(n, alloc);
assert(d.size() == n);
assert(std::distance(d.begin(), d.end()) == n);
assert(static_cast<std::size_t>(std::distance(d.begin(), d.end())) == n);
assert(d.get_allocator() == alloc);
}
#endif

View File

@ -17,6 +17,7 @@
#include <vector>
#include <algorithm>
#include <cassert>
#include <cstddef>
int main()
{
@ -25,7 +26,7 @@ int main()
{
std::vector<bool> b(i,true);
std::vector<bool>::iterator j = std::find(b.begin()+1, b.end(), false);
assert(j-b.begin() == i);
assert(static_cast<std::size_t>(j-b.begin()) == i);
assert(b.end() == j);
}
}
@ -34,7 +35,7 @@ int main()
{
std::vector<bool> b(i,false);
std::vector<bool>::iterator j = std::find(b.begin()+1, b.end(), true);
assert(j-b.begin() == i);
assert(static_cast<std::size_t>(j-b.begin()) == i);
assert(b.end() == j);
}
}

View File

@ -15,6 +15,7 @@
#include <initializer_list>
#include <cassert>
#include <cstddef>
#include "test_macros.h"
@ -27,7 +28,7 @@ struct A
const int* b = il.begin();
const int* e = il.end();
assert(il.size() == 3);
assert(e - b == il.size());
assert(static_cast<std::size_t>(e - b) == il.size());
assert(*b++ == 3);
assert(*b++ == 2);
assert(*b++ == 1);
@ -42,7 +43,7 @@ struct B
const int* b = il.begin();
const int* e = il.end();
assert(il.size() == 3);
assert(e - b == il.size());
assert(static_cast<std::size_t>(e - b) == il.size());
assert(*b++ == 3);
assert(*b++ == 2);
assert(*b++ == 1);

View File

@ -13,6 +13,7 @@
#include <initializer_list>
#include <cassert>
#include <cstddef>
#include "test_macros.h"
@ -25,7 +26,7 @@ struct A
const int* b = begin(il);
const int* e = end(il);
assert(il.size() == 3);
assert(e - b == il.size());
assert(static_cast<std::size_t>(e - b) == il.size());
assert(*b++ == 3);
assert(*b++ == 2);
assert(*b++ == 1);
@ -40,7 +41,7 @@ struct B
const int* b = begin(il);
const int* e = end(il);
assert(il.size() == 3);
assert(e - b == il.size());
assert(static_cast<std::size_t>(e - b) == il.size());
assert(*b++ == 3);
assert(*b++ == 2);
assert(*b++ == 1);

View File

@ -19,6 +19,7 @@
#include <string>
#include <vector>
#include <cassert>
#include <cstddef>
typedef std::codecvt<wchar_t, char, std::mbstate_t> F;
@ -35,8 +36,8 @@ int main()
F::result r = f.in(mbs, from.data(), from.data() + from.size(), from_next,
&to[0], &to[0] + to.size(), to_next);
assert(r == F::ok);
assert(from_next - from.data() == from.size());
assert(to_next - to.data() == expected.size());
assert(to_next - to.data() == expected.size());
assert(static_cast<std::size_t>(from_next - from.data()) == from.size());
assert(static_cast<std::size_t>(to_next - to.data()) == expected.size());
assert(static_cast<std::size_t>(to_next - to.data()) == expected.size());
assert(to == expected);
}

View File

@ -19,6 +19,7 @@
#include <string>
#include <vector>
#include <cassert>
#include <cstddef>
typedef std::codecvt<wchar_t, char, std::mbstate_t> F;
@ -35,8 +36,8 @@ int main()
F::result r = f.out(mbs, from.data(), from.data() + from.size(), from_next,
to.data(), to.data() + to.size(), to_next);
assert(r == F::ok);
assert(from_next - from.data() == from.size());
assert(to_next - to.data() == from.size());
assert(static_cast<std::size_t>(from_next - from.data()) == from.size());
assert(static_cast<std::size_t>(to_next - to.data()) == from.size());
assert(to.data() == std::string("some text"));
}
{
@ -49,8 +50,8 @@ int main()
F::result r = f.out(mbs, from.data(), from.data() + from.size(), from_next,
to.data(), to.data() + to.size(), to_next);
assert(r == F::ok);
assert(from_next - from.data() == from.size());
assert(to_next - to.data() == from.size());
assert(static_cast<std::size_t>(from_next - from.data()) == from.size());
assert(static_cast<std::size_t>(to_next - to.data()) == from.size());
assert(memcmp(to.data(), "some\0text", from.size()) == 0);
}
{
@ -62,8 +63,8 @@ int main()
F::result r = f.out(mbs, from.data(), from.data() + from.size(), from_next,
to.data(), to.data() + to.size()-1, to_next);
assert(r == F::partial);
assert(from_next - from.data() == to.size()-1);
assert(to_next - to.data() == to.size()-1);
assert(static_cast<std::size_t>(from_next - from.data()) == to.size()-1);
assert(static_cast<std::size_t>(to_next - to.data()) == to.size()-1);
assert(to.data() == std::string("some te"));
}
}

View File

@ -17,6 +17,7 @@
#include <valarray>
#include <cassert>
#include <cstddef>
int main()
{
@ -26,6 +27,6 @@ int main()
const unsigned N = sizeof(a)/sizeof(a[0]);
const std::valarray<T> v(a, N);
assert(v[v.size()-1] == 5);
assert(end(v) - begin(v) == v.size());
assert(static_cast<std::size_t>(end(v) - begin(v)) == v.size());
}
}

View File

@ -17,6 +17,7 @@
#include <valarray>
#include <cassert>
#include <cstddef>
int main()
{
@ -27,6 +28,6 @@ int main()
std::valarray<T> v(a, N);
*(end(v) - 1) = 10;
assert(v[v.size()-1] == 10);
assert(end(v) - begin(v) == v.size());
assert(static_cast<std::size_t>(end(v) - begin(v)) == v.size());
}
}

View File

@ -16,6 +16,7 @@
#include <regex>
#include <cassert>
#include <cstddef>
#include "test_macros.h"
void
@ -28,7 +29,7 @@ test()
std::match_results<const char*>::const_iterator i = m.begin();
std::match_results<const char*>::const_iterator e = m.end();
assert(e - i == m.size());
assert(static_cast<std::size_t>(e - i) == m.size());
for (int j = 0; i != e; ++i, ++j)
assert(*i == m[j]);
}

View File

@ -16,6 +16,7 @@
#include <regex>
#include <cassert>
#include <cstddef>
#include "test_macros.h"
void
@ -28,7 +29,7 @@ test()
std::match_results<const char*>::const_iterator i = m.cbegin();
std::match_results<const char*>::const_iterator e = m.cend();
assert(e - i == m.size());
assert(static_cast<std::size_t>(e - i) == m.size());
for (int j = 0; i != e; ++i, ++j)
assert(*i == m[j]);
}

View File

@ -15,6 +15,7 @@
#include <stdexcept>
#include <algorithm>
#include <cassert>
#include <cstddef>
#include "test_macros.h"
#include "test_allocator.h"
@ -61,7 +62,7 @@ test(Tp n, Tp c)
typedef typename S::allocator_type A;
S s2(n, c);
LIBCPP_ASSERT(s2.__invariants());
assert(s2.size() == n);
assert(s2.size() == static_cast<std::size_t>(n));
for (int i = 0; i < n; ++i)
assert(s2[i] == c);
assert(s2.get_allocator() == A());
@ -77,7 +78,7 @@ test(Tp n, Tp c, const A& a)
typedef typename S::traits_type T;
S s2(n, c, a);
LIBCPP_ASSERT(s2.__invariants());
assert(s2.size() == n);
assert(s2.size() == static_cast<std::size_t>(n));
for (int i = 0; i < n; ++i)
assert(s2[i] == c);
assert(s2.get_allocator() == a);

View File

@ -14,6 +14,7 @@
#include <string>
#include <cassert>
#include <cstddef>
#include "min_allocator.h"
@ -29,8 +30,8 @@ test(S s)
assert(e == s.begin());
assert(ce == cs.begin());
}
assert(e - s.begin() == s.size());
assert(ce - cs.begin() == cs.size());
assert(static_cast<std::size_t>(e - s.begin()) == s.size());
assert(static_cast<std::size_t>(ce - cs.begin()) == cs.size());
}
int main()

View File

@ -14,6 +14,7 @@
#include <string>
#include <cassert>
#include <cstddef>
#include "min_allocator.h"
@ -29,8 +30,8 @@ test(S s)
assert(e == s.rbegin());
assert(ce == cs.rbegin());
}
assert(e - s.rbegin() == s.size());
assert(ce - cs.rbegin() == cs.size());
assert(static_cast<std::size_t>(e - s.rbegin()) == s.size());
assert(static_cast<std::size_t>(ce - cs.rbegin()) == cs.size());
}
int main()

View File

@ -13,6 +13,7 @@
#include <string_view>
#include <cassert>
#include <cstddef>
#include "test_macros.h"
@ -38,9 +39,9 @@ test(S s)
assert(ce2 != s.begin());
}
assert( e - s.begin() == s.size());
assert(ce1 - cs.begin() == cs.size());
assert(ce2 - s.cbegin() == s.size());
assert(static_cast<std::size_t>( e - s.begin()) == s.size());
assert(static_cast<std::size_t>(ce1 - cs.begin()) == cs.size());
assert(static_cast<std::size_t>(ce2 - s.cbegin()) == s.size());
assert( e == ce1);
assert( e == ce2);

View File

@ -13,6 +13,7 @@
#include <string_view>
#include <cassert>
#include <cstddef>
#include "test_macros.h"
@ -38,9 +39,9 @@ test(S s)
assert(ce2 != s.rbegin());
}
assert( e - s.rbegin() == s.size());
assert(ce1 - cs.rbegin() == cs.size());
assert(ce2 - s.crbegin() == s.size());
assert(static_cast<std::size_t>( e - s.rbegin()) == s.size());
assert(static_cast<std::size_t>(ce1 - cs.rbegin()) == cs.size());
assert(static_cast<std::size_t>(ce2 - s.crbegin()) == s.size());
assert( e == ce1);
assert( e == ce2);