[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

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@220706 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/algorithm b/include/algorithm
index dbe888f..e003a59 100644
--- a/include/algorithm
+++ b/include/algorithm
@@ -1189,7 +1189,7 @@
 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 @@
         _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 @@
                _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 @@
 _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 @@
 _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 @@
 _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 @@
 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 @@
 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 @@
 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 @@
 _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 @@
 _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 @@
     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 @@
     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 @@
         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 @@
     _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 @@
 __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;
diff --git a/include/deque b/include/deque
index 9b256b7..5602d4a 100644
--- a/include/deque
+++ b/include/deque
@@ -1588,7 +1588,7 @@
 {
     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 @@
         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 @@
     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);
 }
 
diff --git a/include/forward_list b/include/forward_list
index f48f41b..651452f 100644
--- a/include/forward_list
+++ b/include/forward_list
@@ -991,7 +991,7 @@
     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 @@
         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);
diff --git a/include/locale b/include/locale
index 7920f5e..0d01002 100644
--- a/include/locale
+++ b/include/locale
@@ -456,7 +456,7 @@
     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 @@
         // 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 @@
             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 @@
     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 @@
         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;
diff --git a/include/numeric b/include/numeric
index e520c8e..21c3781 100644
--- a/include/numeric
+++ b/include/numeric
@@ -91,7 +91,7 @@
 _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 @@
 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 @@
     {
         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 @@
     {
         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 @@
     {
         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 @@
     {
         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 @@
 void
 iota(_ForwardIterator __first, _ForwardIterator __last, _Tp __value_)
 {
-    for (; __first != __last; ++__first, ++__value_)
+    for (; __first != __last; ++__first, (void) ++__value_)
         *__first = __value_;
 }
 
diff --git a/include/string b/include/string
index 12f541e..fe42bbf 100644
--- a/include/string
+++ b/include/string
@@ -2215,7 +2215,7 @@
         __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());
 }
diff --git a/include/utility b/include/utility
index 4eafda4..6f324db 100644
--- a/include/utility
+++ b/include/utility
@@ -207,7 +207,7 @@
 _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;
 }
diff --git a/test/containers/sequences/forwardlist/forwardlist.cons/assign_range.pass.cpp b/test/containers/sequences/forwardlist/forwardlist.cons/assign_range.pass.cpp
index fb3765d..0b348e6 100644
--- a/test/containers/sequences/forwardlist/forwardlist.cons/assign_range.pass.cpp
+++ b/test/containers/sequences/forwardlist/forwardlist.cons/assign_range.pass.cpp
@@ -70,7 +70,7 @@
         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);
     }
diff --git a/test/support/test_iterators.h b/test/support/test_iterators.h
index cf164be..7150908 100644
--- a/test/support/test_iterators.h
+++ b/test/support/test_iterators.h
@@ -38,6 +38,9 @@
     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 @@
         {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 @@
         {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 @@
     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 @@
         {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>