Fix PR 22541: When values are equal, minmax should return the rightmost one in the initializer_list
llvm-svn: 228839
diff --git a/libcxx/include/algorithm b/libcxx/include/algorithm
index 475ba66..415059d 100644
--- a/libcxx/include/algorithm
+++ b/libcxx/include/algorithm
@@ -2771,7 +2771,7 @@
typedef typename initializer_list<_Tp>::const_iterator _Iter;
_Iter __first = __t.begin();
_Iter __last = __t.end();
- std::pair<_Tp, _Tp> __result ( *__first, *__first );
+ std::pair<_Tp, _Tp> __result(*__first, *__first);
++__first;
if (__t.size() % 2 == 0)
@@ -2786,13 +2786,13 @@
while (__first != __last)
{
_Tp __prev = *__first++;
- if (__comp(__prev, *__first)) {
- if (__comp(__prev, __result.first)) __result.first = __prev;
- if (__comp(__result.second, *__first)) __result.second = *__first;
+ if (__comp(*__first, __prev)) {
+ if ( __comp(*__first, __result.first)) __result.first = *__first;
+ if (!__comp(__prev, __result.second)) __result.second = __prev;
}
else {
- if (__comp(*__first, __result.first)) __result.first = *__first;
- if (__comp(__result.second, __prev)) __result.second = __prev;
+ if ( __comp(__prev, __result.first)) __result.first = __prev;
+ if (!__comp(*__first, __result.second)) __result.second = *__first;
}
__first++;