This is an archive of the discontinued LLVM Phabricator instance.

[libc++] Fix ranges::binary_search() returning true for cases where the element is not in the range
ClosedPublic

Authored by philnik on Mar 3 2023, 4:40 PM.

Details

Diff Detail

Event Timeline

philnik created this revision.Mar 3 2023, 4:40 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 3 2023, 4:40 PM
philnik requested review of this revision.Mar 3 2023, 4:40 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 3 2023, 4:40 PM
Herald added a reviewer: Restricted Project. · View Herald Transcript
Mordante added inline comments.Mar 4 2023, 3:56 AM
libcxx/test/std/algorithms/alg.sorting/alg.binary.search/lower.bound/ranges.lower_bound.pass.cpp
202

Please test the value of *ret too. I know it's kind of double but it makes the test easier to understand.
(The same for upper_bound.)

Do you know why these test don't use std::begin(a) and std::end(a). To me that makes clear it tests the entire range and I don't need to count the elements.

ldionne accepted this revision.Mar 6 2023, 8:46 AM

Let's cherry-pick this one to release/16.x

This revision is now accepted and ready to land.Mar 6 2023, 8:46 AM
philnik added inline comments.Mar 7 2023, 8:28 AM
libcxx/test/std/algorithms/alg.sorting/alg.binary.search/lower.bound/ranges.lower_bound.pass.cpp
202

I think Arthur wanted it that way, but I don't remember exactly why we did it that way.