<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/109327>109327</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang-tidy][readability-container-contains] Also match when comparing find() to string::npos.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-tools-extra,
clang-tidy,
false-negative
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
nicovank
</td>
</tr>
</table>
<pre>
Opening this issue for tracking.
For `std::string` and `std::string_view`, an element is (not) found when comparing `find()` against `std::string::npos` or `std::string_view::npos`, not `end()`. This is not causing false positives since comparing a `find()` result to `end()` doesn't make sense to begin with in those classes, so in fact the check would probably be fixing bugs. (Is there a `bugprone-string-find-end` check?)
As of C++23 the following transformations and derivatives can be added to the check:
```
string.find(...) != std::string::npos; // -> string.contains(...)
string.find(...) != string.npos; // -> string.contains(...)
// Ideally, make this work for any npos, e.g. llvm::StringRef::npos.
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUlEGPszYQhn-NuYxAxgSyHDgkm0b6TpXa3iuDB3Dj2Mhjki__vrKJdqPtVmqliCT2MO_jeccjifRkETtWH1l9yuQaZuc7qwd3k_aS9U49ul8XtNpOEGZNoIlWhNF5CF4OF22ngvET44fteXYeWMMpKFYdWHWg4LWdWMNBWvXNzp83jXfWcCbeQVpAg1e0ATQBE2_WBSZaGN1qFdxntDC46yLjezHVqK1i4o2JNuWfpLYUvlNPv-3iKMZ9C7hhvMZFIOtSOnyRKeCPrQppc5ArRZhRGkJYHOmgb0hA2g74Aiv_ieuRVhMguK8KoBySZWIf4CovCISWMMb1OGkLdx1m0BbC7AhhMJIIKcKSi8ujHAKEGWGYcbjA3a1GweJdL3vzgB5h1D8jUb9OVMQa_6AY7nFj7Ndp8c5ivpUlj8x5pGv4lpFV54j54viBwI3wzsSRiaOokvjojHH31DNeWhqdv8qgnaXUBQq9vsmtUoO0kUoqhSoe8gM9mrGpNPz5SX83sOJZzKIoYocwUbLqBP_ue3UEJs5MnCFn1S_wTDI4G2LTfCT6LxJp7_8nfT63-B8KpTGPaFvyON2su_OXdLGkfUASEO-AxVSAMbfrdpjfk8ZvOH6erfhSpkx1lWqrVmbYlXvR7PdNVVbZ3DVVy3Ff1vVYqrbc1TW-oapF2zZ9P9YDz3QnuNjxtmwF53VZFdWOl41s9ljxneQNsh3Hq9SmiECF81OWpkFX8rYS-8zIHg2lUSLEYKSd8uCcoRx_Bi-ZEEy8f-5o9fhYSvcntzilrojL9SnzXZTJY6eyHTeaAn0KBx1Mmlov2eoTq48epZK9Njo88qcV6PMPU-oTHAw5uMowzF9nyucNja34tYmKbPWmm0NYKC4mJycd5rUvBndl4pxs2r7yxbu_cAhMnFOJiInzs0q3TvwdAAD__3WltCw">