[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
Mon Apr 15 10:02:24 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL358423: [libc++] Fix build failure with _LIBCPP_DEBUG=0 when iterators return values… (authored by thomasanderson, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D60592?vs=194915&id=195214#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60592/new/

https://reviews.llvm.org/D60592

Files:
  libcxx/trunk/include/algorithm
  libcxx/trunk/test/libcxx/algorithms/debug_less.pass.cpp


Index: libcxx/trunk/include/algorithm
===================================================================
--- libcxx/trunk/include/algorithm
+++ libcxx/trunk/include/algorithm
@@ -785,6 +785,15 @@
     __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)
     {
Index: libcxx/trunk/test/libcxx/algorithms/debug_less.pass.cpp
===================================================================
--- libcxx/trunk/test/libcxx/algorithms/debug_less.pass.cpp
+++ libcxx/trunk/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;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D60592.195214.patch
Type: text/x-patch
Size: 2184 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20190415/5eceef70/attachment-0001.bin>


More information about the libcxx-commits mailing list