[PATCH] D112646: [clang-tidy] Add `readability-container-contains` check
Adrian Vogelsgesang via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 18 04:40:04 PST 2022
avogelsgesang updated this revision to Diff 400813.
avogelsgesang marked an inline comment as done.
avogelsgesang added a comment.
Properly support macros as requested by @xazax.hun
Added test cases for
+#define COUNT_ONES(SET) SET.count(1)
+ // CHECK-FIXES: #define COUNT_ONES(SET) SET.count(1)
+ // Rewriting the macro would break the code
+ if (COUNT_ONES(MySet)) {
+ return COUNT_ONES(MySet);
+ }
+#undef COUNT_ONES
+#define COUNT_ONES count(1)
+ // CHECK-FIXES: #define COUNT_ONES count(1)
+ // Rewriting the macro would break the code
+ if (MySet.COUNT_ONES) {
+ return MySet.COUNT_ONES;
+ }
+#undef COUNT_ONES
+#define MY_SET MySet
+ // CHECK-FIXES: #define MY_SET MySet
+ // We still want to rewrite one of the two calls to `count`
+ if (MY_SET.count(1)) {
+ // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: use 'contains' to check for membership [readability-container-contains]
+ // CHECK-FIXES: if (MY_SET.contains(1)) {
+ return MY_SET.count(1);
+ }
Please let me know if I missed any cases
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D112646/new/
https://reviews.llvm.org/D112646
Files:
clang-tools-extra/clang-tidy/readability/CMakeLists.txt
clang-tools-extra/clang-tidy/readability/ContainerContainsCheck.cpp
clang-tools-extra/clang-tidy/readability/ContainerContainsCheck.h
clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/list.rst
clang-tools-extra/docs/clang-tidy/checks/readability-container-contains.rst
clang-tools-extra/test/clang-tidy/checkers/readability-container-contains.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112646.400813.patch
Type: text/x-patch
Size: 23082 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220118/8e2e7421/attachment-0001.bin>
More information about the cfe-commits
mailing list