[libcxx-commits] [PATCH] D60592: [libc++] Fix build failure with _LIBCPP_DEBUG=0 when iterators return values instead of references
Tom Anderson via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Apr 12 10:13:04 PDT 2019
thomasanderson updated this revision to Diff 194915.
thomasanderson marked 4 inline comments as done.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D60592/new/
https://reviews.llvm.org/D60592
Files:
libcxx/include/algorithm
libcxx/test/libcxx/algorithms/debug_less.pass.cpp
Index: libcxx/test/libcxx/algorithms/debug_less.pass.cpp
===================================================================
--- libcxx/test/libcxx/algorithms/debug_less.pass.cpp
+++ libcxx/test/libcxx/algorithms/debug_less.pass.cpp
@@ -235,10 +235,45 @@
}
}
+struct ValueIterator {
+ using iterator_category = std::input_iterator_tag;
+ using value_type = size_t;
+ using difference_type = ptrdiff_t;
+ using reference = size_t;
+ using pointer = size_t*;
+
+ ValueIterator() = default;
+
+ reference operator*() { return 0; }
+ ValueIterator& operator++() { return *this; }
+
+ friend bool operator==(ValueIterator, ValueIterator) { return true; }
+ friend bool operator!=(ValueIterator, ValueIterator) { return false; }
+};
+
+void test_value_iterator() {
+ // Ensure no build failures when iterators return values, not references.
+ assert(0 == std::lexicographical_compare(ValueIterator{}, ValueIterator{},
+ ValueIterator{}, ValueIterator{}));
+}
+
+void test_value_categories() {
+ std::less<int> l;
+ std::__debug_less<std::less<int>> dl(l);
+ int lvalue = 42;
+ const int const_lvalue = 101;
+
+ assert(dl(lvalue, const_lvalue));
+ assert(dl(/*rvalue*/1, lvalue));
+ assert(dl(static_cast<int&&>(1), static_cast<const int&&>(2)));
+}
+
int main(int, char**) {
test_passing();
test_failing();
test_upper_and_lower_bound();
test_non_const_arg_cmp();
+ test_value_iterator();
+ test_value_categories();
return 0;
}
Index: libcxx/include/algorithm
===================================================================
--- libcxx/include/algorithm
+++ libcxx/include/algorithm
@@ -783,6 +783,15 @@
_Compare __comp_;
__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>
bool operator()(_Tp& __x, _Up& __y)
{
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D60592.194915.patch
Type: text/x-patch
Size: 2136 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20190412/2d5fe718/attachment-0001.bin>
More information about the libcxx-commits
mailing list