diff options
| author | Gabor Horvath <xazax.hun@gmail.com> | 2015-12-28 17:20:33 +0000 |
|---|---|---|
| committer | Gabor Horvath <xazax.hun@gmail.com> | 2015-12-28 17:20:33 +0000 |
| commit | 1f30cf6b407f80f203e7c29bb0594d3c3aea4d74 (patch) | |
| tree | ef4a5eeea9bb4631aff0caf124d60698825215bc | |
| parent | a6adc9e790a3537ac05f45b1ab8e7fe7e09d5991 (diff) | |
| download | bcm5719-llvm-1f30cf6b407f80f203e7c29bb0594d3c3aea4d74.tar.gz bcm5719-llvm-1f30cf6b407f80f203e7c29bb0594d3c3aea4d74.zip | |
[clang-tidy] Fix a false positive case in ContainerSizeEmpty check.
llvm-svn: 256504
| -rw-r--r-- | clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp | 13 | ||||
| -rw-r--r-- | clang-tools-extra/test/clang-tidy/readability-container-size-empty.cpp | 8 |
2 files changed, 15 insertions, 6 deletions
diff --git a/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp b/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp index c8f7bae67f8..bb4cd6cfa4a 100644 --- a/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp @@ -126,10 +126,15 @@ 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; + // 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; diff --git a/clang-tools-extra/test/clang-tidy/readability-container-size-empty.cpp b/clang-tools-extra/test/clang-tidy/readability-container-size-empty.cpp index e43feb92450..7fcfb500a25 100644 --- a/clang-tools-extra/test/clang-tidy/readability-container-size-empty.cpp +++ b/clang-tools-extra/test/clang-tidy/readability-container-size-empty.cpp @@ -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 |

