-
Notifications
You must be signed in to change notification settings - Fork 13k
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
clang-tidy: checks "readability-container-contains" does not handle "find()" #79437
Labels
Comments
Interesting, in C++20 this code looks like this:
when in C++17:
And check support only binaryOperator, so it won't work on iterators objects. Looks like support for those 2 need simply be added. |
|
|
nicovank
added a commit
to nicovank/llvm-project
that referenced
this issue
Sep 28, 2024
…ryOperator cases Fix llvm#79437. It works with non-mock `std::map`: ``` # All cases detailed in llvm#79437. > cat tmp.cpp #include <map> bool a(std::map<int, int> &m, int key) { return m.find(key) != m.end(); } bool b(std::map<int, int> &m, int key) { return m.count(key) > 0; } bool c(std::map<int, int> &m, int key) { return m.find(key) == m.end(); } bool d(std::map<int, int> &m, int key) { return m.count(key) == 0; } bool e(std::map<int, int> *m, int key) { return m->find(key) != m->end(); } bool f(std::map<int, int> *m, int key) { return m->find(key) == m->end(); } bool g(std::map<int, int> *m, int key) { return m->count(key) > 0; } bool h(std::map<int, int> *m, int key) { return m->count(key) == 0; } > ./build/bin/clang-tidy -checks="-*,readability-container-contains" tmp.cpp -- -std=c++20 8 warnings generated. tmp.cpp:2:51: warning: use 'contains' to check for membership [readability-container-contains] 2 | bool a(std::map<int, int> &m, int key) { return m.find(key) != m.end(); } | ^~~~ ~~~~~~~~~~ | contains tmp.cpp:3:51: warning: use 'contains' to check for membership [readability-container-contains] 3 | bool b(std::map<int, int> &m, int key) { return m.count(key) > 0; } | ^~~~~ ~~~ | contains tmp.cpp:4:51: warning: use 'contains' to check for membership [readability-container-contains] 4 | bool c(std::map<int, int> &m, int key) { return m.find(key) == m.end(); } | ^~~~ ~~~~~~~~~~ | ! contains tmp.cpp:5:51: warning: use 'contains' to check for membership [readability-container-contains] 5 | bool d(std::map<int, int> &m, int key) { return m.count(key) == 0; } | ^~~~~ ~~~~ | ! contains tmp.cpp:6:52: warning: use 'contains' to check for membership [readability-container-contains] 6 | bool e(std::map<int, int> *m, int key) { return m->find(key) != m->end(); } | ^~~~ ~~~~~~~~~~~ | contains tmp.cpp:7:52: warning: use 'contains' to check for membership [readability-container-contains] 7 | bool f(std::map<int, int> *m, int key) { return m->find(key) == m->end(); } | ^~~~ ~~~~~~~~~~~ | ! contains tmp.cpp:8:52: warning: use 'contains' to check for membership [readability-container-contains] 8 | bool g(std::map<int, int> *m, int key) { return m->count(key) > 0; } | ^~~~~ ~~~ | contains tmp.cpp:9:52: warning: use 'contains' to check for membership [readability-container-contains] 9 | bool h(std::map<int, int> *m, int key) { return m->count(key) == 0; } | ^~~~~ ~~~~ | ! contains ```
nicovank
added a commit
to nicovank/llvm-project
that referenced
this issue
Sep 29, 2024
…ryOperator cases Fix llvm#79437. It works with non-mock `std::map`: ``` # All cases detailed in llvm#79437. > cat tmp.cpp #include <map> bool a(std::map<int, int> &m, int key) { return m.find(key) != m.end(); } bool b(std::map<int, int> &m, int key) { return m.count(key) > 0; } bool c(std::map<int, int> &m, int key) { return m.find(key) == m.end(); } bool d(std::map<int, int> &m, int key) { return m.count(key) == 0; } bool e(std::map<int, int> *m, int key) { return m->find(key) != m->end(); } bool f(std::map<int, int> *m, int key) { return m->find(key) == m->end(); } bool g(std::map<int, int> *m, int key) { return m->count(key) > 0; } bool h(std::map<int, int> *m, int key) { return m->count(key) == 0; } > ./build/bin/clang-tidy -checks="-*,readability-container-contains" tmp.cpp -- -std=c++20 8 warnings generated. tmp.cpp:2:51: warning: use 'contains' to check for membership [readability-container-contains] 2 | bool a(std::map<int, int> &m, int key) { return m.find(key) != m.end(); } | ^~~~ ~~~~~~~~~~ | contains tmp.cpp:3:51: warning: use 'contains' to check for membership [readability-container-contains] 3 | bool b(std::map<int, int> &m, int key) { return m.count(key) > 0; } | ^~~~~ ~~~ | contains tmp.cpp:4:51: warning: use 'contains' to check for membership [readability-container-contains] 4 | bool c(std::map<int, int> &m, int key) { return m.find(key) == m.end(); } | ^~~~ ~~~~~~~~~~ | ! contains tmp.cpp:5:51: warning: use 'contains' to check for membership [readability-container-contains] 5 | bool d(std::map<int, int> &m, int key) { return m.count(key) == 0; } | ^~~~~ ~~~~ | ! contains tmp.cpp:6:52: warning: use 'contains' to check for membership [readability-container-contains] 6 | bool e(std::map<int, int> *m, int key) { return m->find(key) != m->end(); } | ^~~~ ~~~~~~~~~~~ | contains tmp.cpp:7:52: warning: use 'contains' to check for membership [readability-container-contains] 7 | bool f(std::map<int, int> *m, int key) { return m->find(key) == m->end(); } | ^~~~ ~~~~~~~~~~~ | ! contains tmp.cpp:8:52: warning: use 'contains' to check for membership [readability-container-contains] 8 | bool g(std::map<int, int> *m, int key) { return m->count(key) > 0; } | ^~~~~ ~~~ | contains tmp.cpp:9:52: warning: use 'contains' to check for membership [readability-container-contains] 9 | bool h(std::map<int, int> *m, int key) { return m->count(key) == 0; } | ^~~~~ ~~~~ | ! contains ```
nicovank
added a commit
to nicovank/llvm-project
that referenced
this issue
Oct 22, 2024
…ryOperator cases Fix llvm#79437. It works with non-mock `std::map`: ``` # All cases detailed in llvm#79437. > cat tmp.cpp #include <map> bool a(std::map<int, int> &m, int key) { return m.find(key) != m.end(); } bool b(std::map<int, int> &m, int key) { return m.count(key) > 0; } bool c(std::map<int, int> &m, int key) { return m.find(key) == m.end(); } bool d(std::map<int, int> &m, int key) { return m.count(key) == 0; } bool e(std::map<int, int> *m, int key) { return m->find(key) != m->end(); } bool f(std::map<int, int> *m, int key) { return m->find(key) == m->end(); } bool g(std::map<int, int> *m, int key) { return m->count(key) > 0; } bool h(std::map<int, int> *m, int key) { return m->count(key) == 0; } > ./build/bin/clang-tidy -checks="-*,readability-container-contains" tmp.cpp -- -std=c++20 8 warnings generated. tmp.cpp:2:51: warning: use 'contains' to check for membership [readability-container-contains] 2 | bool a(std::map<int, int> &m, int key) { return m.find(key) != m.end(); } | ^~~~ ~~~~~~~~~~ | contains tmp.cpp:3:51: warning: use 'contains' to check for membership [readability-container-contains] 3 | bool b(std::map<int, int> &m, int key) { return m.count(key) > 0; } | ^~~~~ ~~~ | contains tmp.cpp:4:51: warning: use 'contains' to check for membership [readability-container-contains] 4 | bool c(std::map<int, int> &m, int key) { return m.find(key) == m.end(); } | ^~~~ ~~~~~~~~~~ | ! contains tmp.cpp:5:51: warning: use 'contains' to check for membership [readability-container-contains] 5 | bool d(std::map<int, int> &m, int key) { return m.count(key) == 0; } | ^~~~~ ~~~~ | ! contains tmp.cpp:6:52: warning: use 'contains' to check for membership [readability-container-contains] 6 | bool e(std::map<int, int> *m, int key) { return m->find(key) != m->end(); } | ^~~~ ~~~~~~~~~~~ | contains tmp.cpp:7:52: warning: use 'contains' to check for membership [readability-container-contains] 7 | bool f(std::map<int, int> *m, int key) { return m->find(key) == m->end(); } | ^~~~ ~~~~~~~~~~~ | ! contains tmp.cpp:8:52: warning: use 'contains' to check for membership [readability-container-contains] 8 | bool g(std::map<int, int> *m, int key) { return m->count(key) > 0; } | ^~~~~ ~~~ | contains tmp.cpp:9:52: warning: use 'contains' to check for membership [readability-container-contains] 9 | bool h(std::map<int, int> *m, int key) { return m->count(key) == 0; } | ^~~~~ ~~~~ | ! contains ```
NoumanAmir657
pushed a commit
to NoumanAmir657/llvm-project
that referenced
this issue
Nov 4, 2024
…ryOperator cases (llvm#110386) Fix llvm#79437.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$ cat qq.cpp
$ /usr/local/clang-17/bin/clang-tidy '-checks=readability-container-contains' contains.cpp -- -std=c++20
1 warning generated.
/tmp/contains.cpp:8:13: warning: use 'contains' to check for membership [readability-container-contains]
8 | return m.count(key) > 0;
| ^~~~~ ~~~
| contains
Despite https://clang.llvm.org/extra/clang-tidy/checks/readability/container-contains.html, readability-container-contains" does not handle "find()".
The text was updated successfully, but these errors were encountered: