[libcxx-commits] [libcxx] a2fe17c - [libc++] Fix reverse_iterator test when UBSan is enabled

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Wed Mar 4 08:35:52 PST 2020


Author: Louis Dionne
Date: 2020-03-04T11:35:34-05:00
New Revision: a2fe17cdc6501ca0a18218487fc35afef4f5f17a

URL: https://github.com/llvm/llvm-project/commit/a2fe17cdc6501ca0a18218487fc35afef4f5f17a
DIFF: https://github.com/llvm/llvm-project/commit/a2fe17cdc6501ca0a18218487fc35afef4f5f17a.diff

LOG: [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.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iterator/types.pass.cpp b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iterator/types.pass.cpp
index 0efda120d789..14f08a8b371b 100644
--- a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iterator/types.pass.cpp
+++ b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iterator/types.pass.cpp
@@ -34,7 +34,7 @@ template <class It>
 struct find_current
     : private std::reverse_iterator<It>
 {
-    void test() {++(this->current);}
+    void test() { (void)this->current; }
 };
 
 template <class It>
@@ -43,8 +43,7 @@ test()
 {
     typedef std::reverse_iterator<It> R;
     typedef std::iterator_traits<It> T;
-    find_current<It> q;
-    q.test();
+    find_current<It> q; q.test(); // Just test that we can access `.current` from derived classes
     static_assert((std::is_same<typename R::iterator_type, It>::value), "");
     static_assert((std::is_same<typename R::value_type, typename T::value_type>::value), "");
     static_assert((std::is_same<typename R::
diff erence_type, typename T::
diff erence_type>::value), "");
@@ -59,5 +58,5 @@ int main(int, char**)
     test<random_access_iterator<char*> >();
     test<char*>();
 
-  return 0;
+    return 0;
 }


        


More information about the libcxx-commits mailing list