Issue 145665
Summary `bugprone-nondeterministic-pointer-iteration-order` reported with custom comparator
Labels clang-tidy, false-positive
Assignees
Reporter firewave
    ```cpp
#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++.

The warning should not be reported if a custom compare function is provided.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to