Author: xazax Date: Mon Dec 28 11:20:33 2015 New Revision: 256504 URL: http://llvm.org/viewvc/llvm-project?rev=256504&view=rev Log: [clang-tidy] Fix a false positive case in ContainerSizeEmpty check.
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=256504&r1=256503&r2=256504&view=diff ============================================================================== --- clang-tools-extra/trunk/clang-tidy/readability/ContainerSizeEmptyCheck.cpp (original) +++ clang-tools-extra/trunk/clang-tidy/readability/ContainerSizeEmptyCheck.cpp Mon Dec 28 11:20:33 2015 @@ -126,10 +126,15 @@ 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; + // Do not warn for size > 1, 1 < size, size <= 1, 1 >= size. + if (Value == 1) { + if ((OpCode == BinaryOperatorKind::BO_GT && ContainerIsLHS) || + (OpCode == BinaryOperatorKind::BO_LT && !ContainerIsLHS)) + return; + if ((OpCode == BinaryOperatorKind::BO_LE && ContainerIsLHS) || + (OpCode == BinaryOperatorKind::BO_GE && !ContainerIsLHS)) + return; + } if (OpCode == BinaryOperatorKind::BO_NE && Value == 0) Negation = true; 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=256504&r1=256503&r2=256504&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 28 11:20:33 2015 @@ -3,8 +3,8 @@ namespace std { template <typename T> struct vector { vector() {} - unsigned long size() const {} - bool empty() const {} + unsigned long size() const; + bool empty() const; }; } @@ -54,6 +54,10 @@ int main() { ; if (1 < vect.size()) // no warning ; + 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