[clang-tools-extra] r290289 - [clang-tidy] Ignore `size() == 0` in the container implementation.
Alexander Kornienko via cfe-commits
cfe-commits at lists.llvm.org
Wed Dec 21 15:44:23 PST 2016
Author: alexfh
Date: Wed Dec 21 17:44:23 2016
New Revision: 290289
URL: http://llvm.org/viewvc/llvm-project?rev=290289&view=rev
Log:
[clang-tidy] Ignore `size() == 0` in the container implementation.
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=290289&r1=290288&r2=290289&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/readability/ContainerSizeEmptyCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/readability/ContainerSizeEmptyCheck.cpp Wed Dec 21 17:44:23 2016
@@ -58,7 +58,9 @@ void ContainerSizeEmptyCheck::registerMa
hasType(pointsTo(ValidContainer)),
hasType(references(ValidContainer))))
.bind("STLObject")),
- callee(cxxMethodDecl(hasName("size"))), WrongUse)
+ callee(cxxMethodDecl(hasName("size"))), WrongUse,
+ unless(hasAncestor(cxxMethodDecl(
+ ofClass(equalsBoundNode("container"))))))
.bind("SizeCallExpr"),
this);
}
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=290289&r1=290288&r2=290289&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 Wed Dec 21 17:44:23 2016
@@ -61,6 +61,20 @@ public:
class Derived : public Container {
};
+class Container2 {
+public:
+ int size() const;
+ bool empty() const { return size() == 0; }
+};
+
+class Container3 {
+public:
+ int size() const;
+ bool empty() const;
+};
+
+bool Container3::empty() const { return this->size() == 0; }
+
int main() {
std::set<int> intSet;
std::string str;
More information about the cfe-commits
mailing list