Index: libcxx/include/memory =================================================================== --- libcxx/include/memory +++ libcxx/include/memory @@ -1728,23 +1728,23 @@ construct(__a, _VSTD::__to_raw_pointer(__begin2), *__begin1); } - template + template _LIBCPP_INLINE_VISIBILITY static typename enable_if < - (is_same >::value - || !__has_construct::value) && - is_trivially_move_constructible<_Tp>::value, + (is_same::type> >::value + || is_same >::value) && + is_trivially_move_constructible<_DestTp>::value, void >::type - __construct_range_forward(allocator_type&, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2) + __construct_range_forward(allocator_type&, _SourceTp* __begin1, _SourceTp* __end1, _DestTp*& __begin2) { - typedef typename remove_const<_Tp>::type _Vp; + typedef typename remove_const<_DestTp>::type _Vp; ptrdiff_t _Np = __end1 - __begin1; if (_Np > 0) { - _VSTD::memcpy(const_cast<_Vp*>(__begin2), __begin1, _Np * sizeof(_Tp)); + _VSTD::memcpy(const_cast<_Vp*>(__begin2), __begin1, _Np * sizeof(_DestTp)); __begin2 += _Np; } } Index: libcxx/test/std/containers/sequences/vector/vector.cons/construct_iter_iter_alloc.pass.cpp =================================================================== --- libcxx/test/std/containers/sequences/vector/vector.cons/construct_iter_iter_alloc.pass.cpp +++ libcxx/test/std/containers/sequences/vector/vector.cons/construct_iter_iter_alloc.pass.cpp @@ -195,6 +195,17 @@ //C v(It(arr2), It(std::end(arr2)), a); } } + { + using C = std::vector >; + { + ExpectConstructGuard G(1); + C v(arr1, arr1 + 1); + } + { + ExpectConstructGuard G(3); + C v(arr2, arr2 + 3); + } + } #endif } Index: libcxx/test/std/containers/sequences/vector/vector.cons/construct_iter_iter_different_value_type.pass.cpp =================================================================== --- /dev/null +++ libcxx/test/std/containers/sequences/vector/vector.cons/construct_iter_iter_different_value_type.pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template vector(InputIter first, InputIter last); + +// Initialize a vector with a different value type. Make sure initialization +// is performed with each element value, not with a memory blob. + +#include +#include +#include +#include + +int main() +{ + int array[3] = {0, 1, 2}; + std::vector v(array, array + 3); + assert(std::fabs(v[0] - 0.0f) < FLT_EPSILON); + assert(std::fabs(v[1] - 1.0f) < FLT_EPSILON); + assert(std::fabs(v[2] - 2.0f) < FLT_EPSILON); +}