Skip to content

Commit a2fe17c

Browse files
committed
[libc++] Fix reverse_iterator test when UBSan is enabled
The goal of the test was only to check that we could access the `this->current` member of std::reverse_iterator from a derived class, but in doing so we incremented a null iterator, which is UB.
1 parent 71a3168 commit a2fe17c

File tree

1 file changed

+3
-4
lines changed
  • libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iterator

1 file changed

+3
-4
lines changed

libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iterator/types.pass.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ template <class It>
3434
struct find_current
3535
: private std::reverse_iterator<It>
3636
{
37-
void test() {++(this->current);}
37+
void test() { (void)this->current; }
3838
};
3939

4040
template <class It>
@@ -43,8 +43,7 @@ test()
4343
{
4444
typedef std::reverse_iterator<It> R;
4545
typedef std::iterator_traits<It> T;
46-
find_current<It> q;
47-
q.test();
46+
find_current<It> q; q.test(); // Just test that we can access `.current` from derived classes
4847
static_assert((std::is_same<typename R::iterator_type, It>::value), "");
4948
static_assert((std::is_same<typename R::value_type, typename T::value_type>::value), "");
5049
static_assert((std::is_same<typename R::difference_type, typename T::difference_type>::value), "");
@@ -59,5 +58,5 @@ int main(int, char**)
5958
test<random_access_iterator<char*> >();
6059
test<char*>();
6160

62-
return 0;
61+
return 0;
6362
}

0 commit comments

Comments
 (0)