summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarshall Clow <mclow.lists@gmail.com>2017-12-04 18:59:14 +0000
committerMarshall Clow <mclow.lists@gmail.com>2017-12-04 18:59:14 +0000
commitfeb8343281cf723081c189d3e661209490f92ac8 (patch)
treed489167e3e5318d890fdb02ffd7fa44b1a2a261e
parent7eae251bae797e851045ac4c936a3036c350e651 (diff)
downloadbcm5719-llvm-feb8343281cf723081c189d3e661209490f92ac8.tar.gz
bcm5719-llvm-feb8343281cf723081c189d3e661209490f92ac8.zip
Fix PR#35948: generate_n does not accept floating point Size arguments.
llvm-svn: 319675
-rw-r--r--libcxx/include/type_traits5
-rw-r--r--libcxx/test/std/algorithms/alg.modifying.operations/alg.generate/generate_n.pass.cpp23
2 files changed, 23 insertions, 5 deletions
diff --git a/libcxx/include/type_traits b/libcxx/include/type_traits
index 22e39124c33..8485c8c3a9a 100644
--- a/libcxx/include/type_traits
+++ b/libcxx/include/type_traits
@@ -4652,6 +4652,11 @@ long long __convert_to_integral(long long __val) { return __val; }
inline _LIBCPP_INLINE_VISIBILITY
unsigned long long __convert_to_integral(unsigned long long __val) {return __val; }
+template<typename _Fp>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_floating_point<_Fp>::value, long long>::type
+ __convert_to_integral(_Fp __val) { return __val; }
+
#ifndef _LIBCPP_HAS_NO_INT128
inline _LIBCPP_INLINE_VISIBILITY
__int128_t __convert_to_integral(__int128_t __val) { return __val; }
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 a9ccaf4cd95..6a014a9c00c 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
@@ -18,29 +18,42 @@
#include <algorithm>
#include <cassert>
+#include "test_macros.h"
#include "test_iterators.h"
#include "user_defined_integral.hpp"
-typedef UserDefinedIntegral<unsigned> UDI;
-
struct gen_test
{
int operator()() const {return 2;}
};
-template <class Iter>
+template <class Iter, class Size>
void
-test()
+test2()
{
const unsigned n = 4;
int ia[n] = {0};
- assert(std::generate_n(Iter(ia), UDI(n), gen_test()) == Iter(ia+n));
+ assert(std::generate_n(Iter(ia), Size(n), gen_test()) == Iter(ia+n));
assert(ia[0] == 2);
assert(ia[1] == 2);
assert(ia[2] == 2);
assert(ia[3] == 2);
}
+template <class Iter>
+void
+test()
+{
+ test2<Iter, int>();
+ test2<Iter, unsigned int>();
+ test2<Iter, long>();
+ test2<Iter, unsigned long>();
+ test2<Iter, UserDefinedIntegral<unsigned> >();
+ test2<Iter, float>();
+ test2<Iter, double>(); // this is PR#35498
+ test2<Iter, long double>();
+}
+
int main()
{
test<forward_iterator<int*> >();
OpenPOWER on IntegriCloud