Open
Description
#include <algorithm>
#include <vector>
struct S
{
int i() const;
};
void f()
{
std::vector<const S*> v;
std::sort(v.begin(), v.end(), [](const S* s1, const S* s2){
return s1->i() > s2->i();
});
}
<source>:12:5: warning: sorting pointers is nondeterministic [bugprone-nondeterministic-pointer-iteration-order]
12 | std::sort(v.begin(), v.end(), [](const S* s1, const S* s2){
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
13 | return s1->i() > s2->i();
| ~~~~~~~~~~~~~~~~~~~~~~~~~
14 | });
https://godbolt.org/z/xjYe63rY6
This is only reported with libc++ (see #145667).
The warning should not be reported if a custom compare function is provided.