Skip to content

Commit

Permalink
[libc++][test] Adjust move_iterator tests to allow C++20
Browse files Browse the repository at this point in the history
These tests fail due to a couple of changes to `move_iterator` for C++20:

* `move_iterator<I>::operator++(int)` returns `void` in C++20 if `I` doesn't model `forward_iterator`.

* `move_iterator<I>::reference` is calculated in C++20, so `I` must actually have an `operator*() const`.

Differential Revision: https://reviews.llvm.org/D79343
  • Loading branch information
CaseyCarter committed May 7, 2020
1 parent 31d41e3 commit 8615ce2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Expand Up @@ -16,10 +16,20 @@

#include <iterator>
#include <cassert>
#include <utility>

#include "test_macros.h"
#include "test_iterators.h"

#if TEST_STD_VER > 17
template <class It>
void test_single_pass(It i, It x) {
std::move_iterator<It> r(std::move(i));
r++;
assert(std::move(r).base() == x);
}
#endif

template <class It>
void
test(It i, It x)
Expand All @@ -33,7 +43,11 @@ test(It i, It x)
int main(int, char**)
{
char s[] = "123";
#if TEST_STD_VER > 17
test_single_pass(input_iterator<char*>(s), input_iterator<char*>(s + 1));
#else
test(input_iterator<char*>(s), input_iterator<char*>(s+1));
#endif
test(forward_iterator<char*>(s), forward_iterator<char*>(s+1));
test(bidirectional_iterator<char*>(s), bidirectional_iterator<char*>(s+1));
test(random_access_iterator<char*>(s), random_access_iterator<char*>(s+1));
Expand Down
Expand Up @@ -35,6 +35,8 @@ struct DummyIt {
typedef std::ptrdiff_t difference_type;
typedef ValueType* pointer;
typedef Reference reference;

Reference operator*() const;
};

template <class It>
Expand Down

0 comments on commit 8615ce2

Please sign in to comment.