summaryrefslogtreecommitdiffstats
path: root/libcxx/test/std/algorithms/alg.nonmodifying
diff options
context:
space:
mode:
authorEric Fiselier <eric@efcs.ca>2015-02-10 16:46:42 +0000
committerEric Fiselier <eric@efcs.ca>2015-02-10 16:46:42 +0000
commit51544023a955929cbb3d105421b2e59f6be43964 (patch)
treeef3ed22c8d0e24018181afc2b0470d5ce63b3e3b /libcxx/test/std/algorithms/alg.nonmodifying
parent416886793f68a088dd5903caff5f720dd307bfdb (diff)
downloadbcm5719-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.nonmodifying')
-rw-r--r--libcxx/test/std/algorithms/alg.nonmodifying/alg.search/search_n.pass.cpp4
-rw-r--r--libcxx/test/std/algorithms/alg.nonmodifying/alg.search/search_n_pred.pass.cpp6
2 files changed, 10 insertions, 0 deletions
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.search/search_n.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.search/search_n.pass.cpp
index b834da210d3..f7f8ee09279 100644
--- a/libcxx/test/std/algorithms/alg.nonmodifying/alg.search/search_n.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.search/search_n.pass.cpp
@@ -18,6 +18,7 @@
#include <cassert>
#include "test_iterators.h"
+#include "user_defined_integral.hpp"
template <class Iter>
void
@@ -63,6 +64,9 @@ test()
assert(std::search_n(Iter(ic), Iter(ic+sc), 2, 0) == Iter(ic));
assert(std::search_n(Iter(ic), Iter(ic+sc), 3, 0) == Iter(ic));
assert(std::search_n(Iter(ic), Iter(ic+sc), 4, 0) == Iter(ic+sc));
+
+ // Check that we properly convert the size argument to an integral.
+ std::search_n(Iter(ic), Iter(ic+sc), UserDefinedIntegral<unsigned>(0), 0);
}
int main()
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.search/search_n_pred.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.search/search_n_pred.pass.cpp
index 6004b0e0a81..8bc6f4d26bd 100644
--- a/libcxx/test/std/algorithms/alg.nonmodifying/alg.search/search_n_pred.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.search/search_n_pred.pass.cpp
@@ -18,6 +18,7 @@
#include <cassert>
#include "test_iterators.h"
+#include "user_defined_integral.hpp"
struct count_equal
{
@@ -29,6 +30,7 @@ struct count_equal
unsigned count_equal::count = 0;
+
template <class Iter>
void
test()
@@ -138,6 +140,10 @@ test()
assert(std::search_n(Iter(ic), Iter(ic+sc), 4, 0, count_equal()) == Iter(ic+sc));
assert(count_equal::count <= sc);
count_equal::count = 0;
+
+ // Check that we properly convert the size argument to an integral.
+ std::search_n(Iter(ic), Iter(ic+sc), UserDefinedIntegral<unsigned>(4), 0, count_equal());
+ count_equal::count = 0;
}
int main()
OpenPOWER on IntegriCloud