<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/100726>100726</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
`<algorithm>`: `ranges::upper_bound` uses incorrect helper lambda
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
hewillk
</td>
</tr>
</table>
<pre>
https://github.com/llvm/llvm-project/blob/94e966255fb4309f24805273d2e17f63a4e36d17/libcxx/include/__algorithm/ranges_upper_bound.h#L49-L62
The parameter type of the help lambda here is _const_ _lvalue_ reference, which results in it passing two const lvalue to `comp` which may not be invocable.
```cpp
#include <vector>
#include <algorithm>
struct S {
operator int();
operator int() const = delete;
};
int main() {
std::vector<int> v;
auto cmp = [](int, int) { return true; };
auto proj = [](int) { return S{}; };
(void) std::ranges::upper_bound(v, 0, cmp, proj); // hard error in libc++
}
```
https://godbolt.org/z/hxhf6esbv
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVE2PpDgM_TWuizUlcKgABw79MZzmNnsvhWCK7AaCklDdvb9-Fajprh71rrQSMhDH9rP1nlUI5jIzN3B6hNPzQa1xdL4Z-cVY-9ehc_1bM8a4BBAPQC1QezFxXLujdhNQa-311-vb4t2frCNQ21nXAbV1wbWUdDoNXSGyeqCiyk5Uip44LwcpVMFC9nmZEphOv74CtWbWdu0ZqD2flb04b-KYKng1Xzic12Vhf-7cOvfHEUj8KOpvPyRB9gzZw27_GBkX5dXEkT3Gt4XRDRhHxpHtglZNXa9wZM9oAp61m0M849lelV35jJ4H9jxrBnrCl9HoET2H1caAZkYTcUkjmy8YXxxuwbiHYnQIMtNuWkBmt9BJveHsInaMZr46rTrLx3u0ILP90ctyOyFxGwKCeLqyjs6D-P6V82NA7_7NhuhXHfEnQvm4nyC6hb2KzqOZI1AFVIP4D-etNRDP2LPlyO-3oXz--N6smSNOysy3yLuiIfaJN-LhVxtPqYD4jte74mqNDvW0bMV2GgJVG5KnHdCWEz3H1c8Y_ZrA4D2OW5LEwC-yfAr_meBtoZ8zAFVXZ_p0-x31Trr9-4556WrCliWjpyW9Uul9prjLBEfle2Tvt6liIjjQY3rep_iZAPvvb1pzfedsPDp_AWr_BmrH13GQHLrroW9EX4taHbjJS8rrqq5rcRgbXXVDmcm-L3molJRVTlwI0rnI8qrsqoNpKKMiK0nmmRC5OBakSl0OzLKSSg4SiownZewxyTrVPpgQVm7yLAUdrOrYhm1hEM38gpsXiNL-8M22C7r1EqDIrAkxfKSJJlpuUq-_cTedPCT1_NvEZYZr4CRB7bxnHTcxs7_J-bB6-__X1IY7ALW3xq4N_RMAAP__z2WGbQ">