[llvm-branch-commits] [clang-tools-extra] 0dd8f6f - [ClangTidy] NFC: Add more tests for container-size-empty

Stephen Kelly via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Dec 15 15:31:51 PST 2020


Author: Stephen Kelly
Date: 2020-12-15T23:27:38Z
New Revision: 0dd8f6f9035408fc18b4351ae4096a2852aa8fb5

URL: https://github.com/llvm/llvm-project/commit/0dd8f6f9035408fc18b4351ae4096a2852aa8fb5
DIFF: https://github.com/llvm/llvm-project/commit/0dd8f6f9035408fc18b4351ae4096a2852aa8fb5.diff

LOG: [ClangTidy] NFC: Add more tests for container-size-empty

Added: 
    

Modified: 
    clang-tools-extra/test/clang-tidy/checkers/readability-container-size-empty.cpp

Removed: 
    


################################################################################
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 c67d9275bbfb..9100559233e3 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()) {}


        


More information about the llvm-branch-commits mailing list