[clang-tidy] Ignore `size() == 0` in the container implementation.

llvm-svn: 290289
This commit is contained in:
Alexander Kornienko 2016-12-21 23:44:23 +00:00
parent ec9ebba778
commit b5ca17f817
2 changed files with 17 additions and 1 deletions

View File

@ -58,7 +58,9 @@ void ContainerSizeEmptyCheck::registerMatchers(MatchFinder *Finder) {
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);
}

View File

@ -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;