[libcxx] r208096 - Fix PR 19663. Some calls to find(vector<bool>) were returning iterators that were subtly invalid (didn't compare equal). Thanks to Erik Verbruggen for the report (and diagnosis)

Marshall Clow mclow.lists at gmail.com
Tue May 6 08:33:23 PDT 2014


Author: marshall
Date: Tue May  6 10:33:23 2014
New Revision: 208096

URL: http://llvm.org/viewvc/llvm-project?rev=208096&view=rev
Log:
Fix PR 19663. Some calls to find(vector<bool>) were returning iterators that were subtly invalid (didn't compare equal). Thanks to Erik Verbruggen for the report (and diagnosis)

Modified:
    libcxx/trunk/include/__bit_reference
    libcxx/trunk/test/containers/sequences/vector.bool/find.pass.cpp

Modified: libcxx/trunk/include/__bit_reference
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__bit_reference?rev=208096&r1=208095&r2=208096&view=diff
==============================================================================
--- libcxx/trunk/include/__bit_reference (original)
+++ libcxx/trunk/include/__bit_reference Tue May  6 10:33:23 2014
@@ -174,7 +174,7 @@ __find_bool_true(__bit_iterator<_Cp, _Is
         if (__b)
             return _It(__first.__seg_, static_cast<unsigned>(_VSTD::__ctz(__b)));
         if (__n == __dn)
-            return _It(__first.__seg_, __first.__ctz_ + __n);
+            return __first + __n;
         __n -= __dn;
         ++__first.__seg_;
     }
@@ -210,7 +210,7 @@ __find_bool_false(__bit_iterator<_Cp, _I
         if (__b)
             return _It(__first.__seg_, static_cast<unsigned>(_VSTD::__ctz(__b)));
         if (__n == __dn)
-            return _It(__first.__seg_, __first.__ctz_ + __n);
+            return __first + __n;
         __n -= __dn;
         ++__first.__seg_;
     }

Modified: libcxx/trunk/test/containers/sequences/vector.bool/find.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/containers/sequences/vector.bool/find.pass.cpp?rev=208096&r1=208095&r2=208096&view=diff
==============================================================================
--- libcxx/trunk/test/containers/sequences/vector.bool/find.pass.cpp (original)
+++ libcxx/trunk/test/containers/sequences/vector.bool/find.pass.cpp Tue May  6 10:33:23 2014
@@ -25,6 +25,7 @@ int main()
             std::vector<bool> b(i,true);
             std::vector<bool>::iterator j = std::find(b.begin()+1, b.end(), false);
             assert(j-b.begin() == i);
+            assert(b.end() == j);
         }
     }
     {
@@ -33,6 +34,7 @@ int main()
             std::vector<bool> b(i,false);
             std::vector<bool>::iterator j = std::find(b.begin()+1, b.end(), true);
             assert(j-b.begin() == i);
+            assert(b.end() == j);
         }
     }
 }





More information about the cfe-commits mailing list