llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[clang-tidy] `performance-inefficient-algorithm` suggestion does not compile

Open davidmenggx opened this issue 3 months ago • 1 comments

The suggestion generated does not compile:

#include <set>
#include <algorithm>

#define VALUE (1)

bool f(std::set<int> s) {
  return std::find(s.begin(), s.end(), VALUE) != s.end();
}

Suggestion currently is:

<source>:7:10: warning: this STL algorithm call should be replaced with a container method [performance-inefficient-algorithm]
    7 |   return std::find(s.begin(), s.end(), VALUE) != s.end();
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |          s.find()

It should be s.find(VALUE).

Godbolt: https://godbolt.org/z/55v5PcMKE

davidmenggx avatar Aug 19 '26 20:08 davidmenggx

@llvm/issue-subscribers-clang-tidy

Author: David Meng (davidmenggx)

The suggestion generated does not compile:
#include &lt;set&gt;
#include &lt;algorithm&gt;

#define VALUE (1)

bool f(std::set&lt;int&gt; s) {
  return std::find(s.begin(), s.end(), VALUE) != s.end();
}

Suggestion currently is:

&lt;source&gt;:7:10: warning: this STL algorithm call should be replaced with a container method [performance-inefficient-algorithm]
    7 |   return std::find(s.begin(), s.end(), VALUE) != s.end();
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |          s.find()

It should be s.find(VALUE).

Godbolt: https://godbolt.org/z/55v5PcMKE