aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Kelly <steveire@gmail.com>2020-12-14 23:09:32 +0000
committerStephen Kelly <steveire@gmail.com>2020-12-15 23:27:38 +0000
commit0dd8f6f9035408fc18b4351ae4096a2852aa8fb5 (patch)
treee5d680748ffa22a354c8c76c6c44c007bc5cbe8c
parent702f822ca5bbff96401e9ede39f4ae5c7cbc6b05 (diff)
downloadllvm-0dd8f6f9035408fc18b4351ae4096a2852aa8fb5.zip
llvm-0dd8f6f9035408fc18b4351ae4096a2852aa8fb5.tar.gz
llvm-0dd8f6f9035408fc18b4351ae4096a2852aa8fb5.tar.bz2
[ClangTidy] NFC: Add more tests for container-size-empty
-rw-r--r--clang-tools-extra/test/clang-tidy/checkers/readability-container-size-empty.cpp43
1 files changed, 42 insertions, 1 deletions
diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability-container-size-empty.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability-container-size-empty.cpp
index c67d927..9100559 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/readability-container-size-empty.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability-container-size-empty.cpp
@@ -100,7 +100,12 @@ std::string s_func() {
return std::string();
}
-int main() {
+void takesBool(bool)
+{
+
+}
+
+bool returnsBool() {
std::set<int> intSet;
std::string str;
std::string str2;
@@ -397,6 +402,42 @@ int main() {
;
// CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
// CHECK-FIXES: {{^ }}if (derived.empty()){{$}}
+
+ takesBool(derived.size());
+ // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: the 'empty' method should be used
+ // CHECK-FIXES: {{^ }}takesBool(!derived.empty());
+
+ takesBool(derived.size() == 0);
+ // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: the 'empty' method should be used
+ // CHECK-FIXES: {{^ }}takesBool(derived.empty());
+
+ takesBool(derived.size() != 0);
+ // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: the 'empty' method should be used
+ // CHECK-FIXES: {{^ }}takesBool(!derived.empty());
+
+ bool b1 = derived.size();
+ // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: the 'empty' method should be used
+ // CHECK-FIXES: {{^ }}bool b1 = !derived.empty();
+
+ bool b2(derived.size());
+ // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: the 'empty' method should be used
+ // CHECK-FIXES: {{^ }}bool b2(!derived.empty());
+
+ auto b3 = static_cast<bool>(derived.size());
+ // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: the 'empty' method should be used
+ // CHECK-FIXES: {{^ }}auto b3 = static_cast<bool>(!derived.empty());
+
+ auto b4 = (bool)derived.size();
+ // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: the 'empty' method should be used
+ // CHECK-FIXES: {{^ }}auto b4 = (bool)!derived.empty();
+
+ auto b5 = bool(derived.size());
+ // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: the 'empty' method should be used
+ // CHECK-FIXES: {{^ }}auto b5 = bool(!derived.empty());
+
+ return derived.size();
+ // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: the 'empty' method should be used
+ // CHECK-FIXES: {{^ }}return !derived.empty();
}
#define CHECKSIZE(x) if (x.size()) {}