diff options
| author | Eric Fiselier <eric@efcs.ca> | 2015-02-10 16:46:42 +0000 |
|---|---|---|
| committer | Eric Fiselier <eric@efcs.ca> | 2015-02-10 16:46:42 +0000 |
| commit | 51544023a955929cbb3d105421b2e59f6be43964 (patch) | |
| tree | ef3ed22c8d0e24018181afc2b0470d5ce63b3e3b /libcxx/test/std/algorithms/alg.modifying.operations | |
| parent | 416886793f68a088dd5903caff5f720dd307bfdb (diff) | |
| download | bcm5719-llvm-51544023a955929cbb3d105421b2e59f6be43964.tar.gz bcm5719-llvm-51544023a955929cbb3d105421b2e59f6be43964.zip | |
[libcxx] Properly convert the count arguments to the *_n algorithms before use.
Summary:
The requirement on the `Size` type passed to *_n algorithms is that it is convertible to an integral type. This means we can't use a variable of type `Size` directly. Instead we need to convert it to an integral type first. The problem is finding out what integral type to convert it to. `__convert_to_integral` figures out what integral type to convert it to and performs the conversion, It also promotes the resulting integral type so that it is at least as big as an integer. `__convert_to_integral` also has a special case for converting enums. This should only work on non-scoped enumerations because it does not apply an explicit conversion from the enum to its underlying type.
Reviewers: chandlerc, mclow.lists
Reviewed By: mclow.lists
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D7449
llvm-svn: 228704
Diffstat (limited to 'libcxx/test/std/algorithms/alg.modifying.operations')
3 files changed, 20 insertions, 11 deletions
diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/copy_n.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/copy_n.pass.cpp index f594a0bf618..1dba8847c7e 100644 --- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/copy_n.pass.cpp +++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/copy_n.pass.cpp @@ -17,6 +17,9 @@ #include <cassert> #include "test_iterators.h" +#include "user_defined_integral.hpp" + +typedef UserDefinedIntegral<unsigned> UDI; template <class InIter, class OutIter> void @@ -28,7 +31,7 @@ test() ia[i] = i; int ib[N] = {0}; - OutIter r = std::copy_n(InIter(ia), N/2, OutIter(ib)); + OutIter r = std::copy_n(InIter(ia), UDI(N/2), OutIter(ib)); assert(base(r) == ib+N/2); for (unsigned i = 0; i < N/2; ++i) assert(ia[i] == ib[i]); diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.fill/fill_n.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.fill/fill_n.pass.cpp index bffcf1b63cb..6617cd0916f 100644 --- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.fill/fill_n.pass.cpp +++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.fill/fill_n.pass.cpp @@ -18,6 +18,9 @@ #include <cassert> #include "test_iterators.h" +#include "user_defined_integral.hpp" + +typedef UserDefinedIntegral<unsigned> UDI; template <class Iter> void @@ -25,7 +28,7 @@ test_char() { const unsigned n = 4; char ca[n] = {0}; - assert(std::fill_n(Iter(ca), n, char(1)) == std::next(Iter(ca), n)); + assert(std::fill_n(Iter(ca), UDI(n), char(1)) == std::next(Iter(ca), n)); assert(ca[0] == 1); assert(ca[1] == 1); assert(ca[2] == 1); @@ -38,7 +41,7 @@ test_int() { const unsigned n = 4; int ia[n] = {0}; - assert(std::fill_n(Iter(ia), n, 1) == std::next(Iter(ia), n)); + assert(std::fill_n(Iter(ia), UDI(n), 1) == std::next(Iter(ia), n)); assert(ia[0] == 1); assert(ia[1] == 1); assert(ia[2] == 1); @@ -50,7 +53,7 @@ test_int_array() { const unsigned n = 4; int ia[n] = {0}; - assert(std::fill_n(ia, n, static_cast<char>(1)) == std::next(ia, n)); + assert(std::fill_n(ia, UDI(n), static_cast<char>(1)) == std::next(ia, n)); assert(ia[0] == 1); assert(ia[1] == 1); assert(ia[2] == 1); @@ -69,7 +72,7 @@ test_int_array_struct_source() { const unsigned n = 4; int ia[n] = {0}; - assert(std::fill_n(ia, n, source()) == std::next(ia, n)); + assert(std::fill_n(ia, UDI(n), source()) == std::next(ia, n)); assert(ia[0] == 0); assert(ia[1] == 1); assert(ia[2] == 2); @@ -87,7 +90,7 @@ test_struct_array() { const unsigned n = 4; test1 test1a[n] = {0}; - assert(std::fill_n(test1a, n, static_cast<char>(10)) == std::next(test1a, n)); + assert(std::fill_n(test1a, UDI(n), static_cast<char>(10)) == std::next(test1a, n)); assert(test1a[0].c == 11); assert(test1a[1].c == 11); assert(test1a[2].c == 11); @@ -110,7 +113,7 @@ void test5() { A a[3]; - assert(std::fill_n(&a[0], 3, A('a')) == a+3); + assert(std::fill_n(&a[0], UDI(3), A('a')) == a+3); assert(a[0] == A('a')); assert(a[1] == A('a')); assert(a[2] == A('a')); @@ -124,11 +127,11 @@ struct Storage unsigned char b; }; }; - + void test6() { Storage foo[5]; - std::fill_n(&foo[0], 5, Storage()); + std::fill_n(&foo[0], UDI(5), Storage()); } @@ -143,7 +146,7 @@ int main() test_int<bidirectional_iterator<int*> >(); test_int<random_access_iterator<int*> >(); test_int<int*>(); - + test_int_array(); test_int_array_struct_source(); test_struct_array(); diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.generate/generate_n.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.generate/generate_n.pass.cpp index 249419169a1..a9ccaf4cd95 100644 --- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.generate/generate_n.pass.cpp +++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.generate/generate_n.pass.cpp @@ -19,6 +19,9 @@ #include <cassert> #include "test_iterators.h" +#include "user_defined_integral.hpp" + +typedef UserDefinedIntegral<unsigned> UDI; struct gen_test { @@ -31,7 +34,7 @@ test() { const unsigned n = 4; int ia[n] = {0}; - assert(std::generate_n(Iter(ia), n, gen_test()) == Iter(ia+n)); + assert(std::generate_n(Iter(ia), UDI(n), gen_test()) == Iter(ia+n)); assert(ia[0] == 2); assert(ia[1] == 2); assert(ia[2] == 2); |

