diff options
author | Thomas Anderson <thomasanderson@google.com> | 2019-04-15 17:02:15 +0000 |
---|---|---|
committer | Thomas Anderson <thomasanderson@google.com> | 2019-04-15 17:02:15 +0000 |
commit | 3c3ccc0049506c917632f901560e10280d70e729 (patch) | |
tree | 4a9f473f1c04bbc182614c9f67576a0a28af39c3 /libcxx/include/algorithm | |
parent | 09e539fcaebb6362795d352cdcf4a818cf4d0d6a (diff) | |
download | bcm5719-llvm-3c3ccc0049506c917632f901560e10280d70e729.tar.gz bcm5719-llvm-3c3ccc0049506c917632f901560e10280d70e729.zip |
[libc++] Fix build failure with _LIBCPP_DEBUG=0 when iterators return values instead of references
There are many STL algorithms (such as lexicographical_compare) that compare
values pointed to by iterators like so:
__comp(*it1, *it2);
When building with `_LIBCPP_DEBUG=0`, comparators are wrapped in `__debug_less`
which does some additional validation. But `__debug_less::operator()` takes
non-const references, so if the type of `*it1` is int, not int&, then the build
will fail.
This change adds a `const&` overload for `operator()` to fix the build.
Differential Revision: https://reviews.llvm.org/D60592
llvm-svn: 358423
Diffstat (limited to 'libcxx/include/algorithm')
-rw-r--r-- | libcxx/include/algorithm | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/libcxx/include/algorithm b/libcxx/include/algorithm index 22adcc8ed7d..244ae2d5b78 100644 --- a/libcxx/include/algorithm +++ b/libcxx/include/algorithm @@ -785,6 +785,15 @@ struct __debug_less __debug_less(_Compare& __c) : __comp_(__c) {} template <class _Tp, class _Up> + bool operator()(const _Tp& __x, const _Up& __y) + { + bool __r = __comp_(__x, __y); + if (__r) + __do_compare_assert(0, __y, __x); + return __r; + } + + template <class _Tp, class _Up> _LIBCPP_CONSTEXPR_AFTER_CXX17 bool operator()(_Tp& __x, _Up& __y) { |