aboutsummaryrefslogtreecommitdiff
path: root/clang-tools-extra/test/clang-tidy/checkers/readability
diff options
context:
space:
mode:
authorThomas Schenker <thomas.schenker@protonmail.com>2023-12-04 17:30:12 +0100
committerGitHub <noreply@github.com>2023-12-04 17:30:12 +0100
commit8ac84a9555bc25ed9a53ea6a5a09432e18ee9042 (patch)
tree623bde7d757676260ab99385bcf4d1a1d2943a07 /clang-tools-extra/test/clang-tidy/checkers/readability
parent67f387c67e2a1bfa9432cff372462e204e0952bc (diff)
downloadllvm-8ac84a9555bc25ed9a53ea6a5a09432e18ee9042.zip
llvm-8ac84a9555bc25ed9a53ea6a5a09432e18ee9042.tar.gz
llvm-8ac84a9555bc25ed9a53ea6a5a09432e18ee9042.tar.bz2
[clang-tidy] readability-container-contains literal suffixes (#74215)
Before this PR, readability-container-contains fix-its did not handle integer literal suffixes correctly. It e.g. changed ``` MyMap.count(2) != 0U; ``` into ``` MyMap.contains(2)U; ``` With this PR, it correctly changes it to ``` MyMap.contains(2); ```
Diffstat (limited to 'clang-tools-extra/test/clang-tidy/checkers/readability')
-rw-r--r--clang-tools-extra/test/clang-tidy/checkers/readability/container-contains.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/container-contains.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/container-contains.cpp
index 05a4ebc9..0ecb61b 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/readability/container-contains.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/container-contains.cpp
@@ -175,6 +175,37 @@ int nonRewrittenCount(std::multimap<int, int> &MyMap) {
return C1 + C2 + C3 + C4;
}
+// Check different integer literal suffixes
+int testDifferentIntegerLiteralSuffixes(std::map<int, int> &MyMap) {
+
+ auto C1 = MyMap.count(2) != 0U;
+ // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: use 'contains' to check for membership [readability-container-contains]
+ // CHECK-FIXES: auto C1 = MyMap.contains(2);
+ auto C2 = MyMap.count(2) != 0UL;
+ // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: use 'contains' to check for membership [readability-container-contains]
+ // CHECK-FIXES: auto C2 = MyMap.contains(2);
+ auto C3 = 0U != MyMap.count(2);
+ // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: use 'contains' to check for membership [readability-container-contains]
+ // CHECK-FIXES: auto C3 = MyMap.contains(2);
+ auto C4 = 0UL != MyMap.count(2);
+ // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: use 'contains' to check for membership [readability-container-contains]
+ // CHECK-FIXES: auto C4 = MyMap.contains(2);
+ auto C5 = MyMap.count(2) < 1U;
+ // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: use 'contains' to check for membership [readability-container-contains]
+ // CHECK-FIXES: auto C5 = !MyMap.contains(2);
+ auto C6 = MyMap.count(2) < 1UL;
+ // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: use 'contains' to check for membership [readability-container-contains]
+ // CHECK-FIXES: auto C6 = !MyMap.contains(2);
+ auto C7 = 1U > MyMap.count(2);
+ // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: use 'contains' to check for membership [readability-container-contains]
+ // CHECK-FIXES: auto C7 = !MyMap.contains(2);
+ auto C8 = 1UL > MyMap.count(2);
+ // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: use 'contains' to check for membership [readability-container-contains]
+ // CHECK-FIXES: auto C8 = !MyMap.contains(2);
+
+ return C1 + C2 + C3 + C4 + C5 + C6 + C7 + C8;
+}
+
// We don't want to rewrite if the `contains` call is from a macro expansion
int testMacroExpansion(std::unordered_set<int> &MySet) {
#define COUNT_ONES(SET) SET.count(1)