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

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@187908 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Howard Hinnant 2013-08-07 20:42:16 +00:00
parent ab61b2c9f1
commit 36ba399a33
2 changed files with 42 additions and 0 deletions

View File

@ -173,6 +173,8 @@ __find_bool_true(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type
__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, _IsConst> __first, typename _Cp::size_type
__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_;
}

View File

@ -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);
}
}
}