[libcxx] r187908 - Correct logic bug in find optimization for vector<bool>. This fixes http://llvm.org/bugs/show_bug.cgi?id=16816

Howard Hinnant hhinnant at apple.com
Wed Aug 7 13:42:16 PDT 2013


Author: hhinnant
Date: Wed Aug  7 15:42:16 2013
New Revision: 187908

URL: http://llvm.org/viewvc/llvm-project?rev=187908&view=rev
Log:
Correct logic bug in find optimization for vector<bool>.  This fixes http://llvm.org/bugs/show_bug.cgi?id=16816

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

Modified: libcxx/trunk/include/__bit_reference
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__bit_reference?rev=187908&r1=187907&r2=187908&view=diff
==============================================================================
--- libcxx/trunk/include/__bit_reference (original)
+++ libcxx/trunk/include/__bit_reference Wed Aug  7 15:42:16 2013
@@ -173,6 +173,8 @@ __find_bool_true(__bit_iterator<_Cp, _Is
         __storage_type __b = *__first.__seg_ & __m;
         if (__b)
             return _It(__first.__seg_, static_cast<unsigned>(_VSTD::__ctz(__b)));
+        if (__n == __dn)
+            return _It(__first.__seg_, __first.__ctz_ + __n);
         __n -= __dn;
         ++__first.__seg_;
     }
@@ -207,6 +209,8 @@ __find_bool_false(__bit_iterator<_Cp, _I
         __storage_type __b = ~*__first.__seg_ & __m;
         if (__b)
             return _It(__first.__seg_, static_cast<unsigned>(_VSTD::__ctz(__b)));
+        if (__n == __dn)
+            return _It(__first.__seg_, __first.__ctz_ + __n);
         __n -= __dn;
         ++__first.__seg_;
     }

Added: 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=187908&view=auto
==============================================================================
--- libcxx/trunk/test/containers/sequences/vector.bool/find.pass.cpp (added)
+++ libcxx/trunk/test/containers/sequences/vector.bool/find.pass.cpp Wed Aug  7 15:42:16 2013
@@ -0,0 +1,38 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <vector>
+// vector<bool>
+
+// std::find with vector<bool>::iterator
+
+// http://llvm.org/bugs/show_bug.cgi?id=16816
+
+#include <vector>
+#include <cassert>
+
+int main()
+{
+    {
+        for (unsigned i = 1; i < 256; ++i)
+        {
+            std::vector<bool> b(i,true);
+            std::vector<bool>::iterator j = std::find(b.begin()+1, b.end(), false);
+            assert(j-b.begin() == i);
+        }
+    }
+    {
+        for (unsigned i = 1; i < 256; ++i)
+        {
+            std::vector<bool> b(i,false);
+            std::vector<bool>::iterator j = std::find(b.begin()+1, b.end(), true);
+            assert(j-b.begin() == i);
+        }
+    }
+}





More information about the cfe-commits mailing list