aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabor Horvath <xazax.hun@gmail.com>2015-12-21 09:43:52 +0000
committerGabor Horvath <xazax.hun@gmail.com>2015-12-21 09:43:52 +0000
commit5945d5953b29784d363178fead3dc22720c9d62c (patch)
tree6c18c82f8a23c5ce54850f728b9496a61a943f44
parenta1b68e43e2621a2f82ca794d7e73e1fc124d35c7 (diff)
Fix a false positive case in ContainerSizeEmpty check (PR25893).
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@256142 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--clang-tidy/readability/ContainerSizeEmptyCheck.cpp5
-rw-r--r--test/clang-tidy/readability-container-size-empty.cpp4
2 files changed, 9 insertions, 0 deletions
diff --git a/clang-tidy/readability/ContainerSizeEmptyCheck.cpp b/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
index 87ba3144..c8f7bae6 100644
--- a/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
+++ b/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
@@ -126,6 +126,11 @@ void ContainerSizeEmptyCheck::check(const MatchFinder::MatchResult &Result) {
(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 ||
diff --git a/test/clang-tidy/readability-container-size-empty.cpp b/test/clang-tidy/readability-container-size-empty.cpp
index d7f2612b..e43feb92 100644
--- a/test/clang-tidy/readability-container-size-empty.cpp
+++ b/test/clang-tidy/readability-container-size-empty.cpp
@@ -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