<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - libc++ and libstdc++ sometimes choose different overloads for algorithms"
href="https://bugs.llvm.org/show_bug.cgi?id=34536">34536</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>libc++ and libstdc++ sometimes choose different overloads for algorithms
</td>
</tr>
<tr>
<th>Product</th>
<td>libc++
</td>
</tr>
<tr>
<th>Version</th>
<td>5.0
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>All Bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>richard-llvm@metafoo.co.uk
</td>
</tr>
<tr>
<th>Reporter</th>
<td>dlj@google.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org, mclow.lists@gmail.com
</td>
</tr></table>
<p>
<div>
<pre>Example:
=====
#include <algorithm>
#include <iostream>
#include <vector>
struct Base {
Base(int value) : v(value) {}
friend bool operator<(const Base& l, const Base& r) { return l.v < r.v; }
int v;
};
struct Derived : public Base {
using Base::Base;
bool operator<(const Derived& o) { return v > o.v; }
};
int main(void) {
std::vector<Base> b = {{1}, {5}, {0}, {3}};
std::vector<Derived> d = {{0}, {1}, {3}, {5}};
std::cout << std::lower_bound(d.begin(), d.end(), 4)->v << std::endl;
std::sort(b.begin(), b.end());
for (const auto &x : b) std::cout << x.v << " ";
std::cout << std::endl;
std::sort(d.begin(), d.end());
for (const auto &x : d) std::cout << x.v << " ";
std::cout << std::endl;
}
=====
libc++:
=====
$ bin/clang++ -std=c++11 -stdlib=libc++ tmp/ex.cc && ./a.out
5
0 1 3 5
0 1 3 5
=====
libstdc++:
=====
$ bin/clang++ -std=c++11 -stdlib=libstdc++ tmp/ex.cc && ./a.out
0
0 1 3 5
5 3 1 0
=====
This appears to be due to libc++'s requirement that comparison operators be
const. (In some cases, this is diagnosed; but this example specifically ignores
the diagnostic.)
I believe the libc++ behaviour is correct (and libstdc++ has a bug), but I'm
filing this just to double-check.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>