Issue 124794
Summary Misleading fixit from modernize-use-ranges for remove-erase
Labels new issue
Assignees
Reporter chrchr-github
    ~~~c++
void f(std::vector<int>& v) {
 v.erase(std::remove(v.begin(), v.end(), 5), v.end());
}

void g(std::vector<int>& v) {
    auto er = std::ranges::remove(v, 5);
 v.erase(er.begin(), er.end());
}
~~~
~~~
<source>:5:13: warning: use a ranges version of this algorithm [modernize-use-ranges]](_javascript_:;)
    1 | #include <vector>
    2 | #include <algorithm>
    3 | 
    4 | void f(std::vector<int>& v) {
    5 |     v.erase(std::remove(v.begin(), v.end(), 5), v.end());
      |             ^~~~~~~~~~~ ~~~~~~~~~  ~~~~~~~
      | std::ranges::remove v
~~~
https://godbolt.org/z/fd9bzhezE

The naive approach `v.erase(std::remove(v.begin(), v.end(), 5), v.end());` or even `v.erase(std::remove(v.begin(), v.end(), 5));` doesn't compile, and this is not indicated by the fixit.
Also, the code that uses ranges is not shorter or more readable than the original, and requires an additional named variable.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to