Author: xazax
Date: Mon Dec 21 03:43:52 2015
New Revision: 256142

URL: http://llvm.org/viewvc/llvm-project?rev=256142&view=rev
Log:
Fix a false positive case in ContainerSizeEmpty check (PR25893).

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

Modified: 
clang-tools-extra/trunk/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/ContainerSizeEmptyCheck.cpp?rev=256142&r1=256141&r2=256142&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/readability/ContainerSizeEmptyCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/readability/ContainerSizeEmptyCheck.cpp 
Mon Dec 21 03:43:52 2015
@@ -126,6 +126,11 @@ void ContainerSizeEmptyCheck::check(cons
         (OpCode == BinaryOperatorKind::BO_LE && Value == 0 && !ContainerIsLHS))
       return;
 
+    // Do not warn for size > 1, 1 < size.
+    if ((OpCode == BinaryOperatorKind::BO_GT && Value == 1 && ContainerIsLHS) 
||
+        (OpCode == BinaryOperatorKind::BO_LT && Value == 1 && !ContainerIsLHS))
+      return;
+
     if (OpCode == BinaryOperatorKind::BO_NE && Value == 0)
       Negation = true;
     if ((OpCode == BinaryOperatorKind::BO_GT ||

Modified: 
clang-tools-extra/trunk/test/clang-tidy/readability-container-size-empty.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/readability-container-size-empty.cpp?rev=256142&r1=256141&r2=256142&view=diff
==============================================================================
--- 
clang-tools-extra/trunk/test/clang-tidy/readability-container-size-empty.cpp 
(original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/readability-container-size-empty.cpp 
Mon Dec 21 03:43:52 2015
@@ -50,6 +50,10 @@ int main() {
     ;
   // CHECK-MESSAGES: :[[@LINE-2]]:12: warning: the 'empty' method should be 
used
   // CHECK-FIXES: {{^  }}if (!vect.empty()){{$}}
+  if (vect.size() > 1) // no warning
+    ;
+  if (1 < vect.size()) // no warning
+    ;
   if (!vect.size())
     ;
   // CHECK-MESSAGES: :[[@LINE-2]]:8: warning: the 'empty' method should be used


_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to