Author: hhinnant
Date: Sat Sep 21 16:13:54 2013
New Revision: 191145
URL: http://llvm.org/viewvc/llvm-project?rev=191145&view=rev
Log:
Peter Collingbourne: If a pointer is passed as the third argument of the
(iterator,
iterator, allocator) constructor with the intention of it being
implicitly converted to the allocator type, it is possible for overload
resolution to favour the (iterator, iterator, enable_if) constructor.
Eliminate this possibility by moving the enable_if to one of the
existing arguments and removing the third argument.
Modified:
libcxx/trunk/include/vector
libcxx/trunk/test/containers/sequences/vector/vector.cons/construct_iter_iter_alloc.pass.cpp
Modified: libcxx/trunk/include/vector
URL:
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/vector?rev=191145&r1=191144&r2=191145&view=diff
==============================================================================
--- libcxx/trunk/include/vector (original)
+++ libcxx/trunk/include/vector Sat Sep 21 16:13:54 2013
@@ -524,12 +524,13 @@ public:
vector(size_type __n, const_reference __x);
vector(size_type __n, const_reference __x, const allocator_type& __a);
template <class _InputIterator>
- vector(_InputIterator __first, _InputIterator __last,
+ vector(_InputIterator __first,
typename enable_if<__is_input_iterator <_InputIterator>::value
&&
!__is_forward_iterator<_InputIterator>::value
&&
is_constructible<
value_type,
- typename
iterator_traits<_InputIterator>::reference>::value>::type* = 0);
+ typename
iterator_traits<_InputIterator>::reference>::value,
+ _InputIterator>::type __last);
template <class _InputIterator>
vector(_InputIterator __first, _InputIterator __last, const
allocator_type& __a,
typename enable_if<__is_input_iterator <_InputIterator>::value
&&
@@ -538,11 +539,12 @@ public:
value_type,
typename
iterator_traits<_InputIterator>::reference>::value>::type* = 0);
template <class _ForwardIterator>
- vector(_ForwardIterator __first, _ForwardIterator __last,
+ vector(_ForwardIterator __first,
typename
enable_if<__is_forward_iterator<_ForwardIterator>::value &&
is_constructible<
value_type,
- typename
iterator_traits<_ForwardIterator>::reference>::value>::type* = 0);
+ typename
iterator_traits<_ForwardIterator>::reference>::value,
+ _ForwardIterator>::type __last);
template <class _ForwardIterator>
vector(_ForwardIterator __first, _ForwardIterator __last, const
allocator_type& __a,
typename
enable_if<__is_forward_iterator<_ForwardIterator>::value &&
@@ -1072,12 +1074,13 @@ vector<_Tp, _Allocator>::vector(size_typ
template <class _Tp, class _Allocator>
template <class _InputIterator>
-vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last,
+vector<_Tp, _Allocator>::vector(_InputIterator __first,
typename enable_if<__is_input_iterator <_InputIterator>::value &&
!__is_forward_iterator<_InputIterator>::value &&
is_constructible<
value_type,
- typename
iterator_traits<_InputIterator>::reference>::value>::type*)
+ typename
iterator_traits<_InputIterator>::reference>::value,
+ _InputIterator>::type __last)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
@@ -1105,11 +1108,12 @@ vector<_Tp, _Allocator>::vector(_InputIt
template <class _Tp, class _Allocator>
template <class _ForwardIterator>
-vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator
__last,
+vector<_Tp, _Allocator>::vector(_ForwardIterator __first,
typename
enable_if<__is_forward_iterator<_ForwardIterator>::value &&
is_constructible<
value_type,
- typename
iterator_traits<_ForwardIterator>::reference>::value>::type*)
+ typename
iterator_traits<_ForwardIterator>::reference>::value,
+ _ForwardIterator>::type
__last)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
Modified:
libcxx/trunk/test/containers/sequences/vector/vector.cons/construct_iter_iter_alloc.pass.cpp
URL:
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/containers/sequences/vector/vector.cons/construct_iter_iter_alloc.pass.cpp?rev=191145&r1=191144&r2=191145&view=diff
==============================================================================
---
libcxx/trunk/test/containers/sequences/vector/vector.cons/construct_iter_iter_alloc.pass.cpp
(original)
+++
libcxx/trunk/test/containers/sequences/vector/vector.cons/construct_iter_iter_alloc.pass.cpp
Sat Sep 21 16:13:54 2013
@@ -19,9 +19,9 @@
#include "../../../stack_allocator.h"
#include "../../../min_allocator.h"
-template <class C, class Iterator>
+template <class C, class Iterator, class A>
void
-test(Iterator first, Iterator last, const typename C::allocator_type& a)
+test(Iterator first, Iterator last, const A& a)
{
C c(first, last, a);
assert(c.__invariants());
@@ -30,6 +30,17 @@ test(Iterator first, Iterator last, cons
assert(*i == *first);
}
+#if __cplusplus >= 201103L
+
+template <class T>
+struct implicit_conv_allocator : min_allocator<T>
+{
+ implicit_conv_allocator(void* p) {}
+ implicit_conv_allocator(const implicit_conv_allocator&) = default;
+};
+
+#endif
+
int main()
{
{
@@ -52,6 +63,7 @@ int main()
test<std::vector<int, min_allocator<int>> >(bidirectional_iterator<const
int*>(a), bidirectional_iterator<const int*>(an), alloc);
test<std::vector<int, min_allocator<int>> >(random_access_iterator<const
int*>(a), random_access_iterator<const int*>(an), alloc);
test<std::vector<int, min_allocator<int>> >(a, an, alloc);
+ test<std::vector<int, implicit_conv_allocator<int>> >(a, an, nullptr);
}
#endif
}
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits