Issue 109327
Summary [clang-tidy][readability-container-contains] Also match when comparing find() to string::npos.
Labels clang-tools-extra, clang-tidy, false-negative
Assignees
Reporter nicovank
    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.
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to