Fix a couple of unguarded operator, calls in algorithm. Fixes PR#43063. Updated all the heap tests to check this.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@369448 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/algorithm b/include/algorithm
index 91cca5c..b90f33c 100644
--- a/include/algorithm
+++ b/include/algorithm
@@ -3117,10 +3117,10 @@
                          input_iterator_tag) {
 
   _Distance __k = 0;
-  for (; __first != __last && __k < __n; ++__first, (void)++__k)
+  for (; __first != __last && __k < __n; ++__first, (void) ++__k)
     __output_iter[__k] = *__first;
   _Distance __sz = __k;
-  for (; __first != __last; ++__first, (void)++__k) {
+  for (; __first != __last; ++__first, (void) ++__k) {
     _Distance __r = _VSTD::uniform_int_distribution<_Distance>(0, __k)(__g);
     if (__r < __sz)
       __output_iter[__r] = *__first;
@@ -3190,7 +3190,7 @@
     if (__d > 1)
     {
         _Dp __uid;
-        for (--__last, --__d; __first < __last; ++__first, --__d)
+        for (--__last, (void) --__d; __first < __last; ++__first, (void) --__d)
         {
             difference_type __i = __uid(__g, _Pp(0, __d));
             if (__i != difference_type(0))
@@ -3373,7 +3373,7 @@
         // All trues now at start of range, all falses in buffer
         // Move falses back into range, but don't mess up __first which points to first false
         __i = __first;
-        for (value_type* __t2 = __p.first; __t2 < __t; ++__t2, ++__i)
+        for (value_type* __t2 = __p.first; __t2 < __t; ++__t2, (void) ++__i)
             *__i = _VSTD::move(*__t2);
         // __h destructs moved-from values out of the temp buffer, but doesn't deallocate buffer
         return __first;
@@ -3505,7 +3505,7 @@
         __i = ++__first;
         // All trues now at start of range, all falses in buffer
         // Move falses back into range, but don't mess up __first which points to first false
-        for (value_type* __t2 = __p.first; __t2 < __t; ++__t2, ++__i)
+        for (value_type* __t2 = __p.first; __t2 < __t; ++__t2, (void) ++__i)
             *__i = _VSTD::move(*__t2);
         // __h destructs moved-from values out of the temp buffer, but doesn't deallocate buffer
         return __first;
@@ -4428,14 +4428,14 @@
     if (__len1 <= __len2)
     {
         value_type* __p = __buff;
-        for (_BidirectionalIterator __i = __first; __i != __middle; __d.__incr((value_type*)0), (void) ++__i, ++__p)
+        for (_BidirectionalIterator __i = __first; __i != __middle; __d.__incr((value_type*)0), (void) ++__i, (void) ++__p)
             ::new(__p) value_type(_VSTD::move(*__i));
         __half_inplace_merge(__buff, __p, __middle, __last, __first, __comp);
     }
     else
     {
         value_type* __p = __buff;
-        for (_BidirectionalIterator __i = __middle; __i != __last; __d.__incr((value_type*)0), (void) ++__i, ++__p)
+        for (_BidirectionalIterator __i = __middle; __i != __last; __d.__incr((value_type*)0), (void) ++__i, (void) ++__p)
             ::new(__p) value_type(_VSTD::move(*__i));
         typedef reverse_iterator<_BidirectionalIterator> _RBi;
         typedef reverse_iterator<value_type*> _Rv;
@@ -4575,14 +4575,14 @@
     {
         if (__first1 == __last1)
         {
-            for (; __first2 != __last2; ++__first2, ++__result, __d.__incr((value_type*)0))
+            for (; __first2 != __last2; ++__first2, ++__result, (void) __d.__incr((value_type*)0))
                 ::new (__result) value_type(_VSTD::move(*__first2));
             __h.release();
             return;
         }
         if (__first2 == __last2)
         {
-            for (; __first1 != __last1; ++__first1, ++__result, __d.__incr((value_type*)0))
+            for (; __first1 != __last1; ++__first1, ++__result, (void) __d.__incr((value_type*)0))
                 ::new (__result) value_type(_VSTD::move(*__first1));
             __h.release();
             return;
@@ -4612,7 +4612,7 @@
     {
         if (__first2 == __last2)
         {
-            for (; __first1 != __last1; ++__first1, ++__result)
+            for (; __first1 != __last1; ++__first1, (void) ++__result)
                 *__result = _VSTD::move(*__first1);
             return;
         }
@@ -4627,7 +4627,7 @@
             ++__first1;
         }
     }
-    for (; __first2 != __last2; ++__first2, ++__result)
+    for (; __first2 != __last2; ++__first2, (void) ++__result)
         *__result = _VSTD::move(*__first2);
 }
 
@@ -4995,7 +4995,7 @@
 __sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
 {
     typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
-    for (difference_type __n = __last - __first; __n > 1; --__last, --__n)
+    for (difference_type __n = __last - __first; __n > 1; --__last, (void) --__n)
         __pop_heap<_Compare>(__first, __last, __comp, __n);
 }
 
@@ -5065,7 +5065,7 @@
     _RandomAccessIterator __r = __result_first;
     if (__r != __result_last)
     {
-        for (; __first != __last && __r != __result_last; (void) ++__first, ++__r)
+        for (; __first != __last && __r != __result_last; ++__first, (void) ++__r)
             *__r = *__first;
         __make_heap<_Compare>(__result_first, __r, __comp);
         typename iterator_traits<_RandomAccessIterator>::difference_type __len = __r - __result_first;
diff --git a/test/std/algorithms/alg.sorting/alg.heap.operations/is.heap/is_heap.pass.cpp b/test/std/algorithms/alg.sorting/alg.heap.operations/is.heap/is_heap.pass.cpp
index 14b1d17..8ccff2e 100644
--- a/test/std/algorithms/alg.sorting/alg.heap.operations/is.heap/is_heap.pass.cpp
+++ b/test/std/algorithms/alg.sorting/alg.heap.operations/is.heap/is_heap.pass.cpp
@@ -17,6 +17,7 @@
 #include <cassert>
 
 #include "test_macros.h"
+#include "test_iterators.h"
 
 #if TEST_STD_VER > 17
 TEST_CONSTEXPR bool test_constexpr() {
@@ -29,9 +30,13 @@
 
 void test()
 {
+    typedef random_access_iterator<int *> RI;
     int i1[] = {0, 0};
     assert(std::is_heap(i1, i1));
     assert(std::is_heap(i1, i1+1) == (std::is_heap_until(i1, i1+1) == i1+1));
+    assert(std::is_heap(RI(i1), RI(i1)));
+    assert(std::is_heap(RI(i1), RI(i1+1)) == (std::is_heap_until(RI(i1), RI(i1+1)) == RI(i1+1)));
+
     int i2[] = {0, 1};
     int i3[] = {1, 0};
     assert(std::is_heap(i1, i1+2) == (std::is_heap_until(i1, i1+2) == i1+2));
diff --git a/test/std/algorithms/alg.sorting/alg.heap.operations/is.heap/is_heap_comp.pass.cpp b/test/std/algorithms/alg.sorting/alg.heap.operations/is.heap/is_heap_comp.pass.cpp
index 9e34458..b07a3c8 100644
--- a/test/std/algorithms/alg.sorting/alg.heap.operations/is.heap/is_heap_comp.pass.cpp
+++ b/test/std/algorithms/alg.sorting/alg.heap.operations/is.heap/is_heap_comp.pass.cpp
@@ -18,6 +18,7 @@
 #include <cassert>
 
 #include "test_macros.h"
+#include "test_iterators.h"
 
 #if TEST_STD_VER > 17
 TEST_CONSTEXPR bool test_constexpr() {
@@ -30,9 +31,13 @@
 
 void test()
 {
+    typedef random_access_iterator<int *> RI;
     int i1[] = {0, 0};
     assert(std::is_heap(i1, i1, std::greater<int>()));
     assert(std::is_heap(i1, i1+1, std::greater<int>()) == (std::is_heap_until(i1, i1+1, std::greater<int>()) == i1+1));
+    assert(std::is_heap(RI(i1), RI(i1), std::greater<int>()));
+    assert(std::is_heap(RI(i1), RI(i1+1), std::greater<int>()) == (std::is_heap_until(RI(i1), RI(i1+1), std::greater<int>()) == RI(i1+1)));
+
     int i2[] = {0, 1};
     int i3[] = {1, 0};
     assert(std::is_heap(i1, i1+2, std::greater<int>()) == (std::is_heap_until(i1, i1+2, std::greater<int>()) == i1+2));
diff --git a/test/std/algorithms/alg.sorting/alg.heap.operations/is.heap/is_heap_until.pass.cpp b/test/std/algorithms/alg.sorting/alg.heap.operations/is.heap/is_heap_until.pass.cpp
index b9bb3e1..9708db7 100644
--- a/test/std/algorithms/alg.sorting/alg.heap.operations/is.heap/is_heap_until.pass.cpp
+++ b/test/std/algorithms/alg.sorting/alg.heap.operations/is.heap/is_heap_until.pass.cpp
@@ -17,6 +17,7 @@
 #include <cassert>
 
 #include "test_macros.h"
+#include "test_iterators.h"
 
 #if TEST_STD_VER > 17
 TEST_CONSTEXPR bool test_constexpr() {
@@ -29,9 +30,13 @@
 
 void test()
 {
+    typedef random_access_iterator<int *> RI;
     int i1[] = {0, 0};
     assert(std::is_heap_until(i1, i1) == i1);
     assert(std::is_heap_until(i1, i1+1) == i1+1);
+    assert(std::is_heap_until(RI(i1), RI(i1)) == RI(i1));
+    assert(std::is_heap_until(RI(i1), RI(i1+1)) == RI(i1+1));
+
     int i2[] = {0, 1};
     int i3[] = {1, 0};
     assert(std::is_heap_until(i1, i1+2) == i1+2);
diff --git a/test/std/algorithms/alg.sorting/alg.heap.operations/is.heap/is_heap_until_comp.pass.cpp b/test/std/algorithms/alg.sorting/alg.heap.operations/is.heap/is_heap_until_comp.pass.cpp
index 6002f66..1cec544 100644
--- a/test/std/algorithms/alg.sorting/alg.heap.operations/is.heap/is_heap_until_comp.pass.cpp
+++ b/test/std/algorithms/alg.sorting/alg.heap.operations/is.heap/is_heap_until_comp.pass.cpp
@@ -18,6 +18,7 @@
 #include <cassert>
 
 #include "test_macros.h"
+#include "test_iterators.h"
 
 #if TEST_STD_VER > 17
 TEST_CONSTEXPR bool test_constexpr() {
@@ -30,9 +31,13 @@
 
 void test()
 {
+    typedef random_access_iterator<int *> RI;
     int i1[] = {0, 0};
     assert(std::is_heap_until(i1, i1, std::greater<int>()) == i1);
     assert(std::is_heap_until(i1, i1+1, std::greater<int>()) == i1+1);
+    assert(std::is_heap_until(RI(i1), RI(i1), std::greater<int>()) == RI(i1));
+    assert(std::is_heap_until(RI(i1), RI(i1+1), std::greater<int>()) == RI(i1+1));
+
     int i2[] = {0, 1};
     int i3[] = {1, 0};
     assert(std::is_heap_until(i1, i1+2, std::greater<int>()) == i1+2);
diff --git a/test/std/algorithms/alg.sorting/alg.heap.operations/make.heap/make_heap.pass.cpp b/test/std/algorithms/alg.sorting/alg.heap.operations/make.heap/make_heap.pass.cpp
index 76244a9..8042299 100644
--- a/test/std/algorithms/alg.sorting/alg.heap.operations/make.heap/make_heap.pass.cpp
+++ b/test/std/algorithms/alg.sorting/alg.heap.operations/make.heap/make_heap.pass.cpp
@@ -18,6 +18,7 @@
 #include <cassert>
 
 #include "test_macros.h"
+#include "test_iterators.h"
 
 std::mt19937 randomness;
 
@@ -29,6 +30,12 @@
     std::shuffle(ia, ia+N, randomness);
     std::make_heap(ia, ia+N);
     assert(std::is_heap(ia, ia+N));
+
+    typedef random_access_iterator<int *> RI;
+    std::shuffle(RI(ia), RI(ia+N), randomness);
+    std::make_heap(RI(ia), RI(ia+N));
+    assert(std::is_heap(RI(ia), RI(ia+N)));
+
     delete [] ia;
 }
 
diff --git a/test/std/algorithms/alg.sorting/alg.heap.operations/make.heap/make_heap_comp.pass.cpp b/test/std/algorithms/alg.sorting/alg.heap.operations/make.heap/make_heap_comp.pass.cpp
index 0650f74..23c501c 100644
--- a/test/std/algorithms/alg.sorting/alg.heap.operations/make.heap/make_heap_comp.pass.cpp
+++ b/test/std/algorithms/alg.sorting/alg.heap.operations/make.heap/make_heap_comp.pass.cpp
@@ -21,6 +21,7 @@
 
 #include "test_macros.h"
 #include "counting_predicates.hpp"
+#include "test_iterators.h"
 
 struct indirect_less
 {
@@ -40,6 +41,11 @@
     std::shuffle(ia, ia+N, randomness);
     std::make_heap(ia, ia+N, std::greater<int>());
     assert(std::is_heap(ia, ia+N, std::greater<int>()));
+
+    std::shuffle(ia, ia+N, randomness);
+    std::make_heap(random_access_iterator<int *>(ia), 
+                   random_access_iterator<int *>(ia+N), std::greater<int>());
+    assert(std::is_heap(ia, ia+N, std::greater<int>()));
     }
 
 //  Ascending
diff --git a/test/std/algorithms/alg.sorting/alg.heap.operations/pop.heap/pop_heap.pass.cpp b/test/std/algorithms/alg.sorting/alg.heap.operations/pop.heap/pop_heap.pass.cpp
index fa0e112..1282232 100644
--- a/test/std/algorithms/alg.sorting/alg.heap.operations/pop.heap/pop_heap.pass.cpp
+++ b/test/std/algorithms/alg.sorting/alg.heap.operations/pop.heap/pop_heap.pass.cpp
@@ -18,6 +18,7 @@
 #include <cassert>
 
 #include "test_macros.h"
+#include "test_iterators.h"
 
 std::mt19937 randomness;
 
@@ -34,6 +35,18 @@
         assert(std::is_heap(ia, ia+i-1));
     }
     std::pop_heap(ia, ia);
+
+
+    typedef random_access_iterator<int *> RI;
+    std::shuffle(RI(ia), RI(ia+N), randomness);
+    std::make_heap(RI(ia), RI(ia+N));
+    for (int i = N; i > 0; --i)
+    {
+        std::pop_heap(RI(ia), RI(ia+i));
+        assert(std::is_heap(RI(ia), RI(ia+i-1)));
+    }
+    std::pop_heap(RI(ia), RI(ia));
+
     delete [] ia;
 }
 
diff --git a/test/std/algorithms/alg.sorting/alg.heap.operations/pop.heap/pop_heap_comp.pass.cpp b/test/std/algorithms/alg.sorting/alg.heap.operations/pop.heap/pop_heap_comp.pass.cpp
index 63bd152..dc4658f 100644
--- a/test/std/algorithms/alg.sorting/alg.heap.operations/pop.heap/pop_heap_comp.pass.cpp
+++ b/test/std/algorithms/alg.sorting/alg.heap.operations/pop.heap/pop_heap_comp.pass.cpp
@@ -20,6 +20,7 @@
 #include <memory>
 
 #include "test_macros.h"
+#include "test_iterators.h"
 
 struct indirect_less
 {
@@ -44,6 +45,17 @@
         assert(std::is_heap(ia, ia+i-1, std::greater<int>()));
     }
     std::pop_heap(ia, ia, std::greater<int>());
+
+    typedef random_access_iterator<int *> RI;
+    std::shuffle(RI(ia), RI(ia+N), randomness);
+    std::make_heap(RI(ia), RI(ia+N), std::greater<int>());
+    for (int i = N; i > 0; --i)
+    {
+        std::pop_heap(RI(ia), RI(ia+i), std::greater<int>());
+        assert(std::is_heap(RI(ia), RI(ia+i-1), std::greater<int>()));
+    }
+    std::pop_heap(RI(ia), RI(ia), std::greater<int>());
+
     delete [] ia;
 }
 
diff --git a/test/std/algorithms/alg.sorting/alg.heap.operations/push.heap/push_heap.pass.cpp b/test/std/algorithms/alg.sorting/alg.heap.operations/push.heap/push_heap.pass.cpp
index 208bf6e..52f279b 100644
--- a/test/std/algorithms/alg.sorting/alg.heap.operations/push.heap/push_heap.pass.cpp
+++ b/test/std/algorithms/alg.sorting/alg.heap.operations/push.heap/push_heap.pass.cpp
@@ -19,6 +19,7 @@
 #include <cassert>
 
 #include "test_macros.h"
+#include "test_iterators.h"
 
 std::mt19937 randomness;
 
@@ -33,6 +34,15 @@
         std::push_heap(ia, ia+i);
         assert(std::is_heap(ia, ia+i));
     }
+
+    typedef random_access_iterator<int *> RI;
+    std::shuffle(RI(ia), RI(ia+N), randomness);
+    for (int i = 0; i <= N; ++i)
+    {
+        std::push_heap(RI(ia), RI(ia+i));
+        assert(std::is_heap(RI(ia), RI(ia+i)));
+    }
+    
     delete [] ia;
 }
 
diff --git a/test/std/algorithms/alg.sorting/alg.heap.operations/push.heap/push_heap_comp.pass.cpp b/test/std/algorithms/alg.sorting/alg.heap.operations/push.heap/push_heap_comp.pass.cpp
index 4a47f65..3681d87 100644
--- a/test/std/algorithms/alg.sorting/alg.heap.operations/push.heap/push_heap_comp.pass.cpp
+++ b/test/std/algorithms/alg.sorting/alg.heap.operations/push.heap/push_heap_comp.pass.cpp
@@ -21,6 +21,7 @@
 #include <memory>
 
 #include "test_macros.h"
+#include "test_iterators.h"
 
 struct indirect_less
 {
@@ -42,6 +43,15 @@
         std::push_heap(ia, ia+i, std::greater<int>());
         assert(std::is_heap(ia, ia+i, std::greater<int>()));
     }
+
+    typedef random_access_iterator<int *> RI;
+    std::shuffle(RI(ia), RI(ia+N), randomness);
+    for (int i = 0; i <= N; ++i)
+    {
+        std::push_heap(RI(ia), RI(ia+i), std::greater<int>());
+        assert(std::is_heap(RI(ia), RI(ia+i), std::greater<int>()));
+    }
+
     delete [] ia;
 }
 
diff --git a/test/std/algorithms/alg.sorting/alg.heap.operations/sort.heap/sort_heap.pass.cpp b/test/std/algorithms/alg.sorting/alg.heap.operations/sort.heap/sort_heap.pass.cpp
index 7d48b87..30ef345 100644
--- a/test/std/algorithms/alg.sorting/alg.heap.operations/sort.heap/sort_heap.pass.cpp
+++ b/test/std/algorithms/alg.sorting/alg.heap.operations/sort.heap/sort_heap.pass.cpp
@@ -18,6 +18,7 @@
 #include <cassert>
 
 #include "test_macros.h"
+#include "test_iterators.h"
 
 std::mt19937 randomness;
 
@@ -30,6 +31,13 @@
     std::make_heap(ia, ia+N);
     std::sort_heap(ia, ia+N);
     assert(std::is_sorted(ia, ia+N));
+
+    typedef random_access_iterator<int *> RI;
+    std::shuffle(RI(ia), RI(ia+N), randomness);
+    std::make_heap(RI(ia), RI(ia+N));
+    std::sort_heap(RI(ia), RI(ia+N));
+    assert(std::is_sorted(RI(ia), RI(ia+N)));
+
     delete [] ia;
 }
 
diff --git a/test/std/algorithms/alg.sorting/alg.heap.operations/sort.heap/sort_heap_comp.pass.cpp b/test/std/algorithms/alg.sorting/alg.heap.operations/sort.heap/sort_heap_comp.pass.cpp
index 151373b..df791f2 100644
--- a/test/std/algorithms/alg.sorting/alg.heap.operations/sort.heap/sort_heap_comp.pass.cpp
+++ b/test/std/algorithms/alg.sorting/alg.heap.operations/sort.heap/sort_heap_comp.pass.cpp
@@ -20,6 +20,7 @@
 #include <memory>
 
 #include "test_macros.h"
+#include "test_iterators.h"
 
 struct indirect_less
 {
@@ -39,6 +40,12 @@
     std::make_heap(ia, ia+N, std::greater<int>());
     std::sort_heap(ia, ia+N, std::greater<int>());
     assert(std::is_sorted(ia, ia+N, std::greater<int>()));
+
+    typedef random_access_iterator<int *> RI;
+    std::shuffle(RI(ia), RI(ia+N), randomness);
+    std::make_heap(RI(ia), RI(ia+N), std::greater<int>());
+    std::sort_heap(RI(ia), RI(ia+N), std::greater<int>());
+    assert(std::is_sorted(RI(ia), RI(ia+N), std::greater<int>()));
     delete [] ia;
 }