https://bugs.llvm.org/show_bug.cgi?id=34536
Bug ID: 34536
Summary: libc++ and libstdc++ sometimes choose different
overloads for algorithms
Product: libc++
Version: 5.0
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: All Bugs
Assignee: richard-l...@metafoo.co.uk
Reporter: d...@google.com
CC: llvm-bugs@lists.llvm.org, mclow.li...@gmail.com
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.
--
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs