Issue 124815
Summary [clang-tidy] Invalid fixit from modernize-use-ranges for nullptr with std::unique_ptr
Labels clang-tidy
Assignees
Reporter chrchr-github
    ~~~c++
#include <vector>
#include <algorithm>
#include <memory>
#include <ranges>

bool f(const std::vector<std::unique_ptr<int>>& v) {
    return std::find(v.begin(), v.end(), nullptr) == v.end();
}

bool g(const std::vector<std::unique_ptr<int>>& v) {
    return std::ranges::find(v, std::unique_ptr<int>()) == v.end();
}

int main() {
 std::vector<std::unique_ptr<int>> a;
    a.emplace_back();
    return g(a);
}
~~~
~~~
<source>:7:12: warning: use a ranges version of this algorithm [modernize-use-ranges]
    1 | #include <vector>
    2 | #include <algorithm>
    3 | #include <memory>
    4 | #include <ranges>
    5 | 
 6 | bool f(const std::vector<std::unique_ptr<int>>& v) {
    7 | return std::find(v.begin(), v.end(), nullptr) == v.end();
      | ^~~~~~~~~ ~~~~~~~~~  ~~~~~~~
      |            std::ranges::find v
1 warning generated.
~~~
https://godbolt.org/z/zsP6nM9oc
I'm not sure why `ranges::find` does not accept `nullptr` here (as opposed to normal `find`), but it is rejected by all three major compilers.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to