+2017-01-06 Jonathan Wakely <jwakely@redhat.com>
+
+ PR libstdc++/78991
+ * include/bits/predefined_ops.h (_Iter_comp_iter, _Iter_comp_val)
+ (_Val_comp_iter, _Iter_equals_val, _Iter_pred, _Iter_comp_to_val)
+ (_Iter_comp_to_iter, _Iter_negate): Make constructors explicit.
+ * testsuite/25_algorithms/sort/78991.cc: New test.
+
2016-12-19 Ville Voutilainen <ville.voutilainen@gmail.com>
Backport from mainline
operator()(_Iterator1 __it1, _Iterator2 __it2) const
{ return *__it1 < *__it2; }
};
+
_GLIBCXX14_CONSTEXPR
inline _Iter_less_iter
__iter_less_iter()
bool
operator()(_Iterator __it, _Value& __val) const
{ return *__it < __val; }
- };
+ };
inline _Iter_less_val
__iter_less_val()
bool
operator()(_Value& __val, _Iterator __it) const
{ return __val < *__it; }
- };
+ };
inline _Val_less_iter
__val_less_iter()
bool
operator()(_Iterator1 __it1, _Iterator2 __it2) const
{ return *__it1 == *__it2; }
- };
+ };
inline _Iter_equal_to_iter
__iter_equal_to_iter()
bool
operator()(_Iterator __it, _Value& __val) const
{ return *__it == __val; }
- };
+ };
inline _Iter_equal_to_val
__iter_equal_to_val()
struct _Iter_comp_iter
{
_Compare _M_comp;
- _GLIBCXX14_CONSTEXPR
+
+ explicit _GLIBCXX14_CONSTEXPR
_Iter_comp_iter(_Compare __comp)
: _M_comp(__comp)
{ }
{
_Compare _M_comp;
+ explicit
_Iter_comp_val(_Compare __comp)
: _M_comp(__comp)
{ }
{
_Compare _M_comp;
+ explicit
_Val_comp_iter(_Compare __comp)
: _M_comp(__comp)
{ }
{
_Value& _M_value;
+ explicit
_Iter_equals_val(_Value& __value)
: _M_value(__value)
{ }
{
typename std::iterator_traits<_Iterator1>::reference _M_ref;
+ explicit
_Iter_equals_iter(_Iterator1 __it1)
: _M_ref(*__it1)
{ }
{
_Predicate _M_pred;
+ explicit
_Iter_pred(_Predicate __pred)
: _M_pred(__pred)
{ }
{
_Predicate _M_pred;
+ explicit
_Iter_negate(_Predicate __pred)
: _M_pred(__pred)
{ }
--- /dev/null
+// Copyright (C) 2017 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-do compile }
+
+// PR 78991
+// This failed to compile with Clang because the result_of expression causes
+// instantiation of _Iter_comp_iter::operator() outside the immediate context.
+
+#include <algorithm>
+
+struct function
+{
+ function() = default;
+
+ template<typename F, typename = std::result_of_t<F&(int, int)>>
+ function(F) { }
+
+ bool operator()(int x, int y) const { return x < y; }
+};
+
+int main()
+{
+ int a[2]{ 2, 1 };
+ std::sort(a, a+2, function{});
+}