[libcxx] r220706 - [libcxx] Fix use of operator comma where the types can be user defined
Eric Fiselier
eric at efcs.ca
Mon Oct 27 12:28:21 PDT 2014
Author: ericwf
Date: Mon Oct 27 14:28:20 2014
New Revision: 220706
URL: http://llvm.org/viewvc/llvm-project?rev=220706&view=rev
Log:
[libcxx] Fix use of operator comma where the types can be user defined
Summary:
An evil user might overload operator comma. Use a void cast to make sure any user overload is not selected.
Modify all the test iterators to define operator comma.
Reviewers: danalbert, mclow.lists
Reviewed By: mclow.lists
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D5929
Modified:
libcxx/trunk/include/algorithm
libcxx/trunk/include/deque
libcxx/trunk/include/forward_list
libcxx/trunk/include/locale
libcxx/trunk/include/numeric
libcxx/trunk/include/string
libcxx/trunk/include/utility
libcxx/trunk/test/containers/sequences/forwardlist/forwardlist.cons/assign_range.pass.cpp
libcxx/trunk/test/support/test_iterators.h
Modified: libcxx/trunk/include/algorithm
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/algorithm?rev=220706&r1=220705&r2=220706&view=diff
==============================================================================
--- libcxx/trunk/include/algorithm (original)
+++ libcxx/trunk/include/algorithm Mon Oct 27 14:28:20 2014
@@ -1189,7 +1189,7 @@ inline _LIBCPP_INLINE_VISIBILITY
bool
equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _BinaryPredicate __pred)
{
- for (; __first1 != __last1; ++__first1, ++__first2)
+ for (; __first1 != __last1; ++__first1, (void) ++__first2)
if (!__pred(*__first1, *__first2))
return false;
return true;
@@ -1213,7 +1213,7 @@ __equal(_InputIterator1 __first1, _Input
_InputIterator2 __first2, _InputIterator2 __last2, _BinaryPredicate __pred,
input_iterator_tag, input_iterator_tag )
{
- for (; __first1 != __last1 && __first2 != __last2; ++__first1, ++__first2)
+ for (; __first1 != __last1 && __first2 != __last2; ++__first1, (void) ++__first2)
if (!__pred(*__first1, *__first2))
return false;
return __first1 == __last1 && __first2 == __last2;
@@ -1267,7 +1267,7 @@ is_permutation(_ForwardIterator1 __first
_ForwardIterator2 __first2, _BinaryPredicate __pred)
{
// shorten sequences as much as possible by lopping of any equal parts
- for (; __first1 != __last1; ++__first1, ++__first2)
+ for (; __first1 != __last1; ++__first1, (void) ++__first2)
if (!__pred(*__first1, *__first2))
goto __not_done;
return true;
@@ -1745,7 +1745,7 @@ inline _LIBCPP_INLINE_VISIBILITY
_OutputIterator
__copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
{
- for (; __first != __last; ++__first, ++__result)
+ for (; __first != __last; ++__first, (void) ++__result)
*__result = *__first;
return __result;
}
@@ -1874,7 +1874,7 @@ inline _LIBCPP_INLINE_VISIBILITY
_OutputIterator
__move(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
{
- for (; __first != __last; ++__first, ++__result)
+ for (; __first != __last; ++__first, (void) ++__result)
*__result = _VSTD::move(*__first);
return __result;
}
@@ -1950,7 +1950,7 @@ inline _LIBCPP_INLINE_VISIBILITY
_OutputIterator
transform(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _UnaryOperation __op)
{
- for (; __first != __last; ++__first, ++__result)
+ for (; __first != __last; ++__first, (void) ++__result)
*__result = __op(*__first);
return __result;
}
@@ -1961,7 +1961,7 @@ _OutputIterator
transform(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2,
_OutputIterator __result, _BinaryOperation __binary_op)
{
- for (; __first1 != __last1; ++__first1, ++__first2, ++__result)
+ for (; __first1 != __last1; ++__first1, (void) ++__first2, ++__result)
*__result = __binary_op(*__first1, *__first2);
return __result;
}
@@ -1998,7 +1998,7 @@ _OutputIterator
replace_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result,
const _Tp& __old_value, const _Tp& __new_value)
{
- for (; __first != __last; ++__first, ++__result)
+ for (; __first != __last; ++__first, (void) ++__result)
if (*__first == __old_value)
*__result = __new_value;
else
@@ -2014,7 +2014,7 @@ _OutputIterator
replace_copy_if(_InputIterator __first, _InputIterator __last, _OutputIterator __result,
_Predicate __pred, const _Tp& __new_value)
{
- for (; __first != __last; ++__first, ++__result)
+ for (; __first != __last; ++__first, (void) ++__result)
if (__pred(*__first))
*__result = __new_value;
else
@@ -2029,7 +2029,7 @@ inline _LIBCPP_INLINE_VISIBILITY
_OutputIterator
__fill_n(_OutputIterator __first, _Size __n, const _Tp& __value_)
{
- for (; __n > 0; ++__first, --__n)
+ for (; __n > 0; ++__first, (void) --__n)
*__first = __value_;
return __first;
}
@@ -2103,7 +2103,7 @@ inline _LIBCPP_INLINE_VISIBILITY
_OutputIterator
generate_n(_OutputIterator __first, _Size __n, _Generator __gen)
{
- for (; __n > 0; ++__first, --__n)
+ for (; __n > 0; ++__first, (void) --__n)
*__first = __gen();
return __first;
}
@@ -4372,7 +4372,7 @@ __buffered_inplace_merge(_BidirectionalI
if (__len1 <= __len2)
{
value_type* __p = __buff;
- for (_BidirectionalIterator __i = __first; __i != __middle; __d.__incr((value_type*)0), ++__i, ++__p)
+ for (_BidirectionalIterator __i = __first; __i != __middle; __d.__incr((value_type*)0), (void) ++__i, ++__p)
::new(__p) value_type(_VSTD::move(*__i));
__merge<_Compare>(move_iterator<value_type*>(__buff),
move_iterator<value_type*>(__p),
@@ -4383,7 +4383,7 @@ __buffered_inplace_merge(_BidirectionalI
else
{
value_type* __p = __buff;
- for (_BidirectionalIterator __i = __middle; __i != __last; __d.__incr((value_type*)0), ++__i, ++__p)
+ for (_BidirectionalIterator __i = __middle; __i != __last; __d.__incr((value_type*)0), (void) ++__i, ++__p)
::new(__p) value_type(_VSTD::move(*__i));
typedef reverse_iterator<_BidirectionalIterator> _RBi;
typedef reverse_iterator<value_type*> _Rv;
@@ -4408,7 +4408,7 @@ __inplace_merge(_BidirectionalIterator _
if (__len2 == 0)
return;
// shrink [__first, __middle) as much as possible (with no moves), returning if it shrinks to 0
- for (; true; ++__first, --__len1)
+ for (; true; ++__first, (void) --__len1)
{
if (__len1 == 0)
return;
@@ -5067,7 +5067,7 @@ __partial_sort_copy(_InputIterator __fir
_RandomAccessIterator __r = __result_first;
if (__r != __result_last)
{
- for (; __first != __last && __r != __result_last; ++__first, ++__r)
+ for (; __first != __last && __r != __result_last; (void) ++__first, ++__r)
*__r = *__first;
__make_heap<_Compare>(__result_first, __r, __comp);
typename iterator_traits<_RandomAccessIterator>::difference_type __len = __r - __result_first;
@@ -5589,7 +5589,7 @@ bool
__lexicographical_compare(_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2, _InputIterator2 __last2, _Compare __comp)
{
- for (; __first2 != __last2; ++__first1, ++__first2)
+ for (; __first2 != __last2; ++__first1, (void) ++__first2)
{
if (__first1 == __last1 || __comp(*__first1, *__first2))
return true;
Modified: libcxx/trunk/include/deque
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/deque?rev=220706&r1=220705&r2=220706&view=diff
==============================================================================
--- libcxx/trunk/include/deque (original)
+++ libcxx/trunk/include/deque Mon Oct 27 14:28:20 2014
@@ -1588,7 +1588,7 @@ deque<_Tp, _Allocator>::assign(_InputIte
{
iterator __i = __base::begin();
iterator __e = __base::end();
- for (; __f != __l && __i != __e; ++__f, ++__i)
+ for (; __f != __l && __i != __e; ++__f, (void) ++__i)
*__i = *__f;
if (__f != __l)
__append(__f, __l);
@@ -2160,7 +2160,7 @@ deque<_Tp, _Allocator>::insert(const_ite
if (__n > __de)
{
__m = __de < __n / 2 ? _VSTD::next(__f, __de) : _VSTD::prev(__l, __n - __de);
- for (_BiIter __j = __m; __j != __l; ++__i, ++__j, ++__base::size())
+ for (_BiIter __j = __m; __j != __l; ++__i, (void) ++__j, ++__base::size())
__alloc_traits::construct(__a, _VSTD::addressof(*__i), *__j);
__n = __de;
}
@@ -2200,7 +2200,7 @@ deque<_Tp, _Allocator>::__append(_ForIte
if (__n > __back_capacity)
__add_back_capacity(__n - __back_capacity);
// __n <= __back_capacity
- for (iterator __i = __base::end(); __f != __l; ++__i, ++__f, ++__base::size())
+ for (iterator __i = __base::end(); __f != __l; ++__i, (void) ++__f, ++__base::size())
__alloc_traits::construct(__a, _VSTD::addressof(*__i), *__f);
}
Modified: libcxx/trunk/include/forward_list
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/forward_list?rev=220706&r1=220705&r2=220706&view=diff
==============================================================================
--- libcxx/trunk/include/forward_list (original)
+++ libcxx/trunk/include/forward_list Mon Oct 27 14:28:20 2014
@@ -991,7 +991,7 @@ forward_list<_Tp, _Alloc>::assign(_Input
iterator __i = before_begin();
iterator __j = _VSTD::next(__i);
iterator __e = end();
- for (; __j != __e && __f != __l; ++__i, ++__j, ++__f)
+ for (; __j != __e && __f != __l; ++__i, (void) ++__j, ++__f)
*__j = *__f;
if (__j == __e)
insert_after(__i, __f, __l);
@@ -1201,7 +1201,7 @@ forward_list<_Tp, _Alloc>::insert_after(
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
- for (++__f; __f != __l; ++__f, __last = __last->__next_)
+ for (++__f; __f != __l; ++__f, ((void)(__last = __last->__next_)))
{
__h.reset(__node_traits::allocate(__a, 1));
__node_traits::construct(__a, _VSTD::addressof(__h->__value_), *__f);
Modified: libcxx/trunk/include/locale
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/locale?rev=220706&r1=220705&r2=220706&view=diff
==============================================================================
--- libcxx/trunk/include/locale (original)
+++ libcxx/trunk/include/locale Mon Oct 27 14:28:20 2014
@@ -456,7 +456,7 @@ __scan_keyword(_InputIterator& __b, _Inp
size_t __n_does_match = 0; // but none of them definitely do
// Initialize all statuses to __might_match, except for "" keywords are __does_match
unsigned char* __st = __status;
- for (_ForwardIterator __ky = __kb; __ky != __ke; ++__ky, ++__st)
+ for (_ForwardIterator __ky = __kb; __ky != __ke; ++__ky, (void) ++__st)
{
if (!__ky->empty())
*__st = __might_match;
@@ -482,7 +482,7 @@ __scan_keyword(_InputIterator& __b, _Inp
// If the keyword doesn't match this character, then change the keyword
// to doesn't match
__st = __status;
- for (_ForwardIterator __ky = __kb; __ky != __ke; ++__ky, ++__st)
+ for (_ForwardIterator __ky = __kb; __ky != __ke; ++__ky, (void) ++__st)
{
if (*__st == __might_match)
{
@@ -516,7 +516,7 @@ __scan_keyword(_InputIterator& __b, _Inp
if (__n_might_match + __n_does_match > 1)
{
__st = __status;
- for (_ForwardIterator __ky = __kb; __ky != __ke; ++__ky, ++__st)
+ for (_ForwardIterator __ky = __kb; __ky != __ke; ++__ky, (void) ++__st)
{
if (*__st == __does_match && __ky->size() != __indx+1)
{
@@ -531,7 +531,7 @@ __scan_keyword(_InputIterator& __b, _Inp
if (__b == __e)
__err |= ios_base::eofbit;
// Return the first matching result
- for (__st = __status; __kb != __ke; ++__kb, ++__st)
+ for (__st = __status; __kb != __ke; ++__kb, (void) ++__st)
if (*__st == __does_match)
break;
if (__kb == __ke)
@@ -1857,7 +1857,7 @@ __get_up_to_n_digits(_InputIterator& __b
return 0;
}
int __r = __ct.narrow(__c, 0) - '0';
- for (++__b, --__n; __b != __e && __n > 0; ++__b, --__n)
+ for (++__b, (void) --__n; __b != __e && __n > 0; ++__b, (void) --__n)
{
// get next digit
__c = *__b;
Modified: libcxx/trunk/include/numeric
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/numeric?rev=220706&r1=220705&r2=220706&view=diff
==============================================================================
--- libcxx/trunk/include/numeric (original)
+++ libcxx/trunk/include/numeric Mon Oct 27 14:28:20 2014
@@ -91,7 +91,7 @@ inline _LIBCPP_INLINE_VISIBILITY
_Tp
inner_product(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _Tp __init)
{
- for (; __first1 != __last1; ++__first1, ++__first2)
+ for (; __first1 != __last1; ++__first1, (void) ++__first2)
__init = __init + *__first1 * *__first2;
return __init;
}
@@ -102,7 +102,7 @@ _Tp
inner_product(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2,
_Tp __init, _BinaryOperation1 __binary_op1, _BinaryOperation2 __binary_op2)
{
- for (; __first1 != __last1; ++__first1, ++__first2)
+ for (; __first1 != __last1; ++__first1, (void) ++__first2)
__init = __binary_op1(__init, __binary_op2(*__first1, *__first2));
return __init;
}
@@ -116,7 +116,7 @@ partial_sum(_InputIterator __first, _Inp
{
typename iterator_traits<_InputIterator>::value_type __t(*__first);
*__result = __t;
- for (++__first, ++__result; __first != __last; ++__first, ++__result)
+ for (++__first, (void) ++__result; __first != __last; ++__first, (void) ++__result)
{
__t = __t + *__first;
*__result = __t;
@@ -135,7 +135,7 @@ partial_sum(_InputIterator __first, _Inp
{
typename iterator_traits<_InputIterator>::value_type __t(*__first);
*__result = __t;
- for (++__first, ++__result; __first != __last; ++__first, ++__result)
+ for (++__first, (void) ++__result; __first != __last; ++__first, (void) ++__result)
{
__t = __binary_op(__t, *__first);
*__result = __t;
@@ -153,7 +153,7 @@ adjacent_difference(_InputIterator __fir
{
typename iterator_traits<_InputIterator>::value_type __t1(*__first);
*__result = __t1;
- for (++__first, ++__result; __first != __last; ++__first, ++__result)
+ for (++__first, (void) ++__result; __first != __last; ++__first, (void) ++__result)
{
typename iterator_traits<_InputIterator>::value_type __t2(*__first);
*__result = __t2 - __t1;
@@ -173,7 +173,7 @@ adjacent_difference(_InputIterator __fir
{
typename iterator_traits<_InputIterator>::value_type __t1(*__first);
*__result = __t1;
- for (++__first, ++__result; __first != __last; ++__first, ++__result)
+ for (++__first, (void) ++__result; __first != __last; ++__first, (void) ++__result)
{
typename iterator_traits<_InputIterator>::value_type __t2(*__first);
*__result = __binary_op(__t2, __t1);
@@ -188,7 +188,7 @@ inline _LIBCPP_INLINE_VISIBILITY
void
iota(_ForwardIterator __first, _ForwardIterator __last, _Tp __value_)
{
- for (; __first != __last; ++__first, ++__value_)
+ for (; __first != __last; ++__first, (void) ++__value_)
*__first = __value_;
}
Modified: libcxx/trunk/include/string
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/string?rev=220706&r1=220705&r2=220706&view=diff
==============================================================================
--- libcxx/trunk/include/string (original)
+++ libcxx/trunk/include/string Mon Oct 27 14:28:20 2014
@@ -2215,7 +2215,7 @@ basic_string<_CharT, _Traits, _Allocator
__set_long_cap(__cap+1);
__set_long_size(__sz);
}
- for (; __first != __last; ++__first, ++__p)
+ for (; __first != __last; ++__first, (void) ++__p)
traits_type::assign(*__p, *__first);
traits_type::assign(*__p, value_type());
}
Modified: libcxx/trunk/include/utility
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/utility?rev=220706&r1=220705&r2=220706&view=diff
==============================================================================
--- libcxx/trunk/include/utility (original)
+++ libcxx/trunk/include/utility Mon Oct 27 14:28:20 2014
@@ -207,7 +207,7 @@ inline _LIBCPP_INLINE_VISIBILITY
_ForwardIterator2
swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2)
{
- for(; __first1 != __last1; ++__first1, ++__first2)
+ for(; __first1 != __last1; ++__first1, (void) ++__first2)
swap(*__first1, *__first2);
return __first2;
}
Modified: libcxx/trunk/test/containers/sequences/forwardlist/forwardlist.cons/assign_range.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/containers/sequences/forwardlist/forwardlist.cons/assign_range.pass.cpp?rev=220706&r1=220705&r2=220706&view=diff
==============================================================================
--- libcxx/trunk/test/containers/sequences/forwardlist/forwardlist.cons/assign_range.pass.cpp (original)
+++ libcxx/trunk/test/containers/sequences/forwardlist/forwardlist.cons/assign_range.pass.cpp Mon Oct 27 14:28:20 2014
@@ -70,7 +70,7 @@ int main()
typedef input_iterator<const T*> I;
c.assign(I(std::begin(t0)), I(std::end(t0)));
int n = 0;
- for (C::const_iterator i = c.cbegin(); i != c.cend(); ++i, ++n)
+ for (C::const_iterator i = c.cbegin(); i != c.cend(); ++i, (void) ++n)
assert(*i == 10+n);
assert(n == 4);
}
Modified: libcxx/trunk/test/support/test_iterators.h
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/support/test_iterators.h?rev=220706&r1=220705&r2=220706&view=diff
==============================================================================
--- libcxx/trunk/test/support/test_iterators.h (original)
+++ libcxx/trunk/test/support/test_iterators.h Mon Oct 27 14:28:20 2014
@@ -38,6 +38,9 @@ public:
output_iterator& operator++() {++it_; return *this;}
output_iterator operator++(int)
{output_iterator tmp(*this); ++(*this); return tmp;}
+
+ template <class T>
+ void operator,(T const &);
};
template <class It>
@@ -71,6 +74,9 @@ public:
{return x.it_ == y.it_;}
friend bool operator!=(const input_iterator& x, const input_iterator& y)
{return !(x == y);}
+
+ template <class T>
+ void operator,(T const &);
};
template <class T, class U>
@@ -120,6 +126,9 @@ public:
{return x.it_ == y.it_;}
friend bool operator!=(const forward_iterator& x, const forward_iterator& y)
{return !(x == y);}
+
+ template <class T>
+ void operator,(T const &);
};
template <class T, class U>
@@ -168,6 +177,9 @@ public:
bidirectional_iterator& operator--() {--it_; return *this;}
bidirectional_iterator operator--(int)
{bidirectional_iterator tmp(*this); --(*this); return tmp;}
+
+ template <class T>
+ void operator,(T const &);
};
template <class T, class U>
@@ -227,6 +239,9 @@ public:
{random_access_iterator tmp(*this); tmp -= n; return tmp;}
reference operator[](difference_type n) const {return it_[n];}
+
+ template <class T>
+ void operator,(T const &);
};
template <class T, class U>
More information about the cfe-commits
mailing list