From 2bb0f75a8015991bb802ea617f17cce9e935150d Mon Sep 17 00:00:00 2001 From: Billy Robert O'Neal III Date: Wed, 3 Apr 2019 00:07:18 +0000 Subject: [PATCH] [libcxx] [test] Use ptrdiff_t rather than int in splice_after_range.pass.cpp to avoid narrowing from pointer subtraction to int warnings. Reviewed as https://reviews.llvm.org/D60104 llvm-svn: 357546 --- .../forwardlist.ops/splice_after_range.pass.cpp | 47 +++++++++++----------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/splice_after_range.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/splice_after_range.pass.cpp index 3205007..741e586 100644 --- a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/splice_after_range.pass.cpp +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/splice_after_range.pass.cpp @@ -11,27 +11,28 @@ // void splice_after(const_iterator p, forward_list&& x, // const_iterator first, const_iterator last); +#include #include #include #include #include "min_allocator.h" -typedef int T; +typedef ptrdiff_t T; const T t1[] = {0, 1, 2, 3, 4, 5, 6, 7}; const T t2[] = {10, 11, 12, 13, 14, 15}; -const int size_t1 = std::end(t1) - std::begin(t1); -const int size_t2 = std::end(t2) - std::begin(t2); +const ptrdiff_t size_t1 = std::end(t1) - std::begin(t1); +const ptrdiff_t size_t2 = std::end(t2) - std::begin(t2); template void -testd(const C& c, int p, int f, int l) +testd(const C& c, ptrdiff_t p, ptrdiff_t f, ptrdiff_t l) { typename C::const_iterator i = c.begin(); - int n1 = 0; + ptrdiff_t n1 = 0; for (; n1 < p; ++n1, ++i) assert(*i == t1[n1]); - for (int n2 = f; n2 < l-1; ++n2, ++i) + for (ptrdiff_t n2 = f; n2 < l-1; ++n2, ++i) assert(*i == t2[n2]); for (; n1 < size_t1; ++n1, ++i) assert(*i == t1[n1]); @@ -40,11 +41,11 @@ testd(const C& c, int p, int f, int l) template void -tests(const C& c, int p, int f, int l) +tests(const C& c, ptrdiff_t p, ptrdiff_t f, ptrdiff_t l) { typename C::const_iterator i = c.begin(); - int n = 0; - int d = l > f+1 ? l-1-f : 0; + ptrdiff_t n = 0; + ptrdiff_t d = l > f+1 ? l-1-f : 0; if (d == 0 || p == f) { for (n = 0; n < size_t1; ++n, ++i) @@ -80,11 +81,11 @@ int main(int, char**) { // splicing different containers typedef std::forward_list C; - for (int f = 0; f <= size_t2+1; ++f) + for (ptrdiff_t f = 0; f <= size_t2+1; ++f) { - for (int l = f; l <= size_t2+1; ++l) + for (ptrdiff_t l = f; l <= size_t2+1; ++l) { - for (int p = 0; p <= size_t1; ++p) + for (ptrdiff_t p = 0; p <= size_t1; ++p) { C c1(std::begin(t1), std::end(t1)); C c2(std::begin(t2), std::end(t2)); @@ -97,11 +98,11 @@ int main(int, char**) } // splicing within same container - for (int f = 0; f <= size_t1+1; ++f) + for (ptrdiff_t f = 0; f <= size_t1+1; ++f) { - for (int l = f; l <= size_t1; ++l) + for (ptrdiff_t l = f; l <= size_t1; ++l) { - for (int p = 0; p <= f; ++p) + for (ptrdiff_t p = 0; p <= f; ++p) { C c1(std::begin(t1), std::end(t1)); @@ -109,7 +110,7 @@ int main(int, char**) next(c1.cbefore_begin(), f), next(c1.cbefore_begin(), l)); tests(c1, p, f, l); } - for (int p = l; p <= size_t1; ++p) + for (ptrdiff_t p = l; p <= size_t1; ++p) { C c1(std::begin(t1), std::end(t1)); @@ -124,11 +125,11 @@ int main(int, char**) { // splicing different containers typedef std::forward_list> C; - for (int f = 0; f <= size_t2+1; ++f) + for (ptrdiff_t f = 0; f <= size_t2+1; ++f) { - for (int l = f; l <= size_t2+1; ++l) + for (ptrdiff_t l = f; l <= size_t2+1; ++l) { - for (int p = 0; p <= size_t1; ++p) + for (ptrdiff_t p = 0; p <= size_t1; ++p) { C c1(std::begin(t1), std::end(t1)); C c2(std::begin(t2), std::end(t2)); @@ -141,11 +142,11 @@ int main(int, char**) } // splicing within same container - for (int f = 0; f <= size_t1+1; ++f) + for (ptrdiff_t f = 0; f <= size_t1+1; ++f) { - for (int l = f; l <= size_t1; ++l) + for (ptrdiff_t l = f; l <= size_t1; ++l) { - for (int p = 0; p <= f; ++p) + for (ptrdiff_t p = 0; p <= f; ++p) { C c1(std::begin(t1), std::end(t1)); @@ -153,7 +154,7 @@ int main(int, char**) next(c1.cbefore_begin(), f), next(c1.cbefore_begin(), l)); tests(c1, p, f, l); } - for (int p = l; p <= size_t1; ++p) + for (ptrdiff_t p = l; p <= size_t1; ++p) { C c1(std::begin(t1), std::end(t1)); -- 2.7.4