-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[clang-tidy][readability-container-contains] Also match when comparing find() to string::npos. #109327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@llvm/issue-subscribers-clang-tidy Author: Nicolas van Kempen (nicovank)
Opening this issue for tracking.
For As of C++23 the following transformations and derivatives can be added to the check:
|
I would like to try adding it to |
The interfaces of I think I'm not sure if duplicating the code is fine, or should I reuse the code between |
In this case I think it's okay to duplicate code, but I don't think it's necessary. It makes no sense to compare other (non-string) containers to In Assuming this feature gets in at some point, since it essentially replaces |
Thanks for your suggestion, I created a PoC for this. The current matcher requires the container to have a method called Is it possible to check whether the parameter of |
FYI #79437 details some additional shortcomings. |
In my experience, working with types in Clang-Tidy is annoying. There is no easy way to find if types are equivalent (especially if pointer/references are involved) and no easy way to check if things are convertible. I'm personally not against removing the type check entirely for |
Opening this issue for tracking.
For
std::string
andstd::string_view
, an element is (not) found when comparingfind()
againststd::string::npos
orstd::string_view::npos
, notend()
. This is not causing false positives since comparing afind()
result toend()
doesn't make sense to begin with in those classes, so in fact the check would probably be fixing bugs. (Is there abugprone-string-find-end
check?)As of C++23 the following transformations and derivatives can be added to the check:
The text was updated successfully, but these errors were encountered: