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/test | |
| 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/test')
| -rw-r--r-- | libcxx/test/libcxx/algorithms/debug_less.pass.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/libcxx/test/libcxx/algorithms/debug_less.pass.cpp b/libcxx/test/libcxx/algorithms/debug_less.pass.cpp index 4f9285421fc..538630364b8 100644 --- a/libcxx/test/libcxx/algorithms/debug_less.pass.cpp +++ b/libcxx/test/libcxx/algorithms/debug_less.pass.cpp @@ -235,10 +235,45 @@ void test_non_const_arg_cmp() { } } +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; } |

