<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<div style="color: rgb(34, 34, 34); font-family: Arial, Helvetica, sans-serif; font-size: small; background-color: rgb(255, 255, 255)">
I'm working on some code that compares two different types with std::upper_bound and does so with a custom lambda, which takes both parameters as type "auto". When building normally, this compiles fine. When building with -D_LIBCPP_DEBUG=1, this fails and somewhere
 in the template magic, libc++ seems to confuse the two types and pass them into the lambda backwards.</div>
<div style="color: rgb(34, 34, 34); font-family: Arial, Helvetica, sans-serif; font-size: small; background-color: rgb(255, 255, 255)">
<br>
</div>
<div style="color: rgb(34, 34, 34); font-family: Arial, Helvetica, sans-serif; font-size: small; background-color: rgb(255, 255, 255)">
Here is some minimal code to reproduce, and the corresponding compilation error:</div>
<br style="color: rgb(34, 34, 34); font-family: Arial, Helvetica, sans-serif; font-size: small; background-color: rgb(255, 255, 255)">
<div style="color: rgb(34, 34, 34); font-family: Arial, Helvetica, sans-serif; font-size: small; background-color: rgb(255, 255, 255)">
<div style="color: rgb(212, 212, 212); background-color: rgb(30, 30, 30); font-family: "Fira Code", Menlo, Monaco, "Courier New", monospace; font-size: 13px; line-height: 18px">
<div><span style="color: rgb(197, 134, 192)">#include</span><span style="color: rgb(86, 156, 214)"> </span><span style="color: rgb(206, 145, 120)"><algorithm></span></div>
<div><span style="color: rgb(197, 134, 192)">#include</span><span style="color: rgb(86, 156, 214)"> </span><span style="color: rgb(206, 145, 120)"><vector></span></div>
<br>
<div><span style="color: rgb(86, 156, 214)">struct</span> <span style="color: rgb(78, 201, 176)">T1</span> {</div>
<div>  <span style="color: rgb(86, 156, 214)">int</span> i;</div>
<div>};</div>
<br>
<div><span style="color: rgb(86, 156, 214)">int</span> <span style="color: rgb(220, 220, 170)">main</span>(<span style="color: rgb(86, 156, 214)">int</span> argc,
<span style="color: rgb(86, 156, 214)">char</span> <span style="color: rgb(86, 156, 214)">const</span>* argv[]) {</div>
<div>  std::vector<T1> t1_vec = {{.<span style="color: rgb(156, 220, 254)">i</span> =
<span style="color: rgb(181, 206, 168)">1</span>}, {.<span style="color: rgb(156, 220, 254)">i</span> =
<span style="color: rgb(181, 206, 168)">3</span>}};</div>
<br>
<div>  <span style="color: rgb(220, 220, 170)">std::upper_bound</span>(t1_vec.<span style="color: rgb(220, 220, 170)">begin</span>(), t1_vec.<span style="color: rgb(220, 220, 170)">end</span>(),
<span style="color: rgb(181, 206, 168)">2</span>,</div>
<div>                   [](<span style="color: rgb(86, 156, 214)">const</span> <span style="color: rgb(86, 156, 214)">auto</span>& a,
<span style="color: rgb(86, 156, 214)">const</span> <span style="color: rgb(86, 156, 214)">auto</span>& b) {
<span style="color: rgb(197, 134, 192)">return</span> a < b.<span style="color: rgb(156, 220, 254)">i</span>; });</div>
<div>  <span style="color: rgb(197, 134, 192)">return</span> <span style="color: rgb(181, 206, 168)">0</span>;</div>
<div>}</div>
<br>
</div>
</div>
<div style="color: rgb(34, 34, 34); font-size: 13px; background-color: rgb(255, 255, 255); font-family: "Fira Code", Menlo, Monaco, "Courier New", monospace; line-height: 18px">
<br>
</div>
<div style="color: rgb(34, 34, 34); font-size: 13px; background-color: rgb(255, 255, 255); font-family: "Fira Code", Menlo, Monaco, "Courier New", monospace; line-height: 18px">
</div>
<span style="font-family: Consolas, Courier, monospace; font-size: 9pt; background-color: rgb(204, 204, 204);">experimental/upper_bound.cpp:14:67: error: member reference base type</span><span><br>
</span>
<div><span style="font-family: Consolas, Courier, monospace; font-size: 9pt; background-color: rgb(204, 204, 204);"> 'const int' is not a structure or union</span><br>
</div>
<div><span style="font-family: Consolas, Courier, monospace; font-size: 9pt; background-color: rgb(204, 204, 204);">                   [](const auto& a, const auto& b) { return a < b.i; });</span><br>
</div>
<div><span style="font-family: Consolas, Courier, monospace; font-size: 9pt; background-color: rgb(204, 204, 204);">                                                                 ~^~</span><br>
</div>
<div><span style="font-family: Consolas, Courier, monospace; font-size: 9pt; background-color: rgb(204, 204, 204);">external/llvm_toolchain/bin/../include/c++/v1/algorithm:777:20: note: in instantiation of function template specialization 'main(int, const char
 **)::(anonymous class)::operator()<T1, int>' requested here</span><br>
</div>
<div><span style="font-family: Consolas, Courier, monospace; font-size: 9pt; background-color: rgb(204, 204, 204);">    decltype((void)_VSTD::declval<_Compare&>()(</span><br>
</div>
<div><span style="font-family: Consolas, Courier, monospace; font-size: 9pt; background-color: rgb(204, 204, 204);">                   ^</span><br>
</div>
<div><span style="font-family: Consolas, Courier, monospace; font-size: 9pt; background-color: rgb(204, 204, 204);">external/llvm_toolchain/bin/../include/c++/v1/__config:473:15: note: expanded from macro '_VSTD'</span><br>
</div>
<div><span style="font-family: Consolas, Courier, monospace; font-size: 9pt; background-color: rgb(204, 204, 204);">#define _VSTD std::_LIBCPP_NAMESPACE</span><br>
</div>
<div><span style="font-family: Consolas, Courier, monospace; font-size: 9pt; background-color: rgb(204, 204, 204);">              ^</span><br>
</div>
<div><span style="font-family: Consolas, Courier, monospace; font-size: 9pt; background-color: rgb(204, 204, 204);">external/llvm_toolchain/bin/../include/c++/v1/algorithm:771:13: note: while substituting deduced template arguments into function template '__do_compare_assert'
 [with _LHS = T1, _RHS = int]</span><br>
</div>
<div><span style="font-family: Consolas, Courier, monospace; font-size: 9pt; background-color: rgb(204, 204, 204);">            __do_compare_assert(0, __y, __x);</span><br>
</div>
<div><span style="font-family: Consolas, Courier, monospace; font-size: 9pt; background-color: rgb(204, 204, 204);">            ^</span><br>
</div>
<div><span style="font-family: Consolas, Courier, monospace; font-size: 9pt; background-color: rgb(204, 204, 204);">external/llvm_toolchain/bin/../include/c++/v1/algorithm:4249:13: note: in instantiation of function template specialization 'std::__1::__debug_less<(lambda
 at experimental/upper_bound.cpp:14:20)>::operator()<int, T1>' requested here</span><br>
</div>
<div><span style="font-family: Consolas, Courier, monospace; font-size: 9pt; background-color: rgb(204, 204, 204);">        if (__comp(__value_, *__m))</span><br>
</div>
<div><span style="font-family: Consolas, Courier, monospace; font-size: 9pt; background-color: rgb(204, 204, 204);">            ^</span><br>
</div>
<div><span style="font-family: Consolas, Courier, monospace; font-size: 9pt; background-color: rgb(204, 204, 204);">external/llvm_toolchain/bin/../include/c++/v1/algorithm:4268:12: note: in instantiation of function template specialization 'std::__1::__upper_bound<std::__1::__debug_less<(lambda
 at experimental/upper_bound.cpp:14:20)> &, std::__1::__wrap_iter<T1 *>, int>' requested here</span><br>
</div>
<div><span style="font-family: Consolas, Courier, monospace; font-size: 9pt; background-color: rgb(204, 204, 204);">    return __upper_bound<_Comp_ref>(__first, __last, __value_, __c);</span><br>
</div>
<div><span style="font-family: Consolas, Courier, monospace; font-size: 9pt; background-color: rgb(204, 204, 204);">           ^</span><br>
</div>
<div><span style="font-family: Consolas, Courier, monospace; font-size: 9pt; background-color: rgb(204, 204, 204);">experimental/upper_bound.cpp:13:8: note: in instantiation of function template specialization 'std::__1::upper_bound<std::__1::__wrap_iter<T1
 *>, int, (lambda at experimental/upper_bound.cpp:14:20)>' requested here</span><br>
</div>
<span style="font-family: Consolas, Courier, monospace; font-size: 9pt; background-color: rgb(204, 204, 204);">  std::upper_bound(t1_vec.begin(), t1_vec.end(), 2,</span><br>
</div>
</body>
</html>