<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/124906>124906</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang-tidy] False negative modernize-use-ranges when using getter function
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-tidy
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
chrchr-github
</td>
</tr>
</table>
<pre>
~~~c++
#include <algorithm>
#include <ranges>
#include <vector>
struct S {
std::vector<int> v;
const std::vector<int>& get() const { return v; }
};
bool f(S& s) {
auto it = std::find(s.get().begin(), s.get().end(), 0); // no warning
auto it2 = std::find(s.v.begin(), s.v.end(), 0);
return it == it2;
}
~~~
~~~
<source>:12:16: warning: use a ranges version of this algorithm [modernize-use-ranges]
12 | auto it2 = std::find(s.v.begin(), s.v.end(), 0);
| ^~~~~~~~~ ~~~~~~~~~~~ ~~~~~~~~~
| std::ranges::find s.v
1 warning generated.
~~~
https://godbolt.org/z/EEvEnrWWs
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJysVEmOqzwQPk2xKSWCMkOyYEEGLvAWb22gAv5F7JZtaHUvOPsvCEl63D0L2aAavsHG0jnVauYckgMkp0AOvjM2rztbd3bTKt8NVVCZ5i2fpqkGOsxPWAAJpet-aBhBHGXfGqt8dwVx_ha0UrfsfoqMXHtj10hYOG-H2uMfhGyGQOcbEAWI4p53VNqDOOMIYklAxNpo53_NBEqxZQ-0A9qvuZAd0LIfrF76IGSnGT473ZpCWFTG9HgB2v2Z691cujJCRDl4g8ojiNMT9qJ0A7Rz2wfYtuJW6ds70BE_hnhJXgPhvM40qAQqURt8lVYr3X7Go18Ax-9A448Aa7tV-U3A3FJ5WoUvPkzT9JhBHJ0ZbM2zk6KIaJ5SEMWDoihwcIwSb3uMI1unjEZzQd8ph49zgZAcrqZhq9U7bwbHm_VUJKcbsYgQsuO_VotLU0jO0zpweg58fnxK_zIeLO7n-M5oBoewiO5uYMuarfTcbB8Wdt6_LCXL7ramqUzvt8a2QOU7UHk-j2dt__51QZOLZi_2MuA8ysQuSsIwzoIup_iSctrUTHFziUiEYidlVnFcJWGTJRSonEJKwoj2UUQZZds0TuUuTUUTRrumpgrikK9S9du-H68zdqCcGziPKN6HadDLinu3_P5EdS91u_GqeQOi-Tqw-Vy1qYbWQRz2ynn37OOV75eL40NZcsJS9o5Rcyu9Ghl_2nd87Vjj4G62ec8WL4OuvTI6GGyff_FtuYW2tbkClTP6umxerPmPaw9ULpIcULmqGnP6PwAA__-MBXQV">