forked from OSchip/llvm-project
[clang-tidy] readability-container-size-empty fix for (*x).size()
llvm-svn: 298316
This commit is contained in:
parent
9bf7037ccd
commit
f6cd367874
|
@ -56,8 +56,7 @@ void ContainerSizeEmptyCheck::registerMatchers(MatchFinder *Finder) {
|
||||||
Finder->addMatcher(
|
Finder->addMatcher(
|
||||||
cxxMemberCallExpr(on(expr(anyOf(hasType(ValidContainer),
|
cxxMemberCallExpr(on(expr(anyOf(hasType(ValidContainer),
|
||||||
hasType(pointsTo(ValidContainer)),
|
hasType(pointsTo(ValidContainer)),
|
||||||
hasType(references(ValidContainer))))
|
hasType(references(ValidContainer))))),
|
||||||
.bind("STLObject")),
|
|
||||||
callee(cxxMethodDecl(hasName("size"))), WrongUse,
|
callee(cxxMethodDecl(hasName("size"))), WrongUse,
|
||||||
unless(hasAncestor(cxxMethodDecl(
|
unless(hasAncestor(cxxMethodDecl(
|
||||||
ofClass(equalsBoundNode("container"))))))
|
ofClass(equalsBoundNode("container"))))))
|
||||||
|
@ -69,7 +68,7 @@ void ContainerSizeEmptyCheck::check(const MatchFinder::MatchResult &Result) {
|
||||||
const auto *MemberCall =
|
const auto *MemberCall =
|
||||||
Result.Nodes.getNodeAs<CXXMemberCallExpr>("SizeCallExpr");
|
Result.Nodes.getNodeAs<CXXMemberCallExpr>("SizeCallExpr");
|
||||||
const auto *BinaryOp = Result.Nodes.getNodeAs<BinaryOperator>("SizeBinaryOp");
|
const auto *BinaryOp = Result.Nodes.getNodeAs<BinaryOperator>("SizeBinaryOp");
|
||||||
const auto *E = Result.Nodes.getNodeAs<Expr>("STLObject");
|
const auto *E = MemberCall->getImplicitObjectArgument();
|
||||||
FixItHint Hint;
|
FixItHint Hint;
|
||||||
std::string ReplacementText =
|
std::string ReplacementText =
|
||||||
Lexer::getSourceText(CharSourceRange::getTokenRange(E->getSourceRange()),
|
Lexer::getSourceText(CharSourceRange::getTokenRange(E->getSourceRange()),
|
||||||
|
|
|
@ -168,6 +168,10 @@ int main() {
|
||||||
;
|
;
|
||||||
// CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
|
// CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
|
||||||
// CHECK-FIXES: {{^ }}if (vect3->empty()){{$}}
|
// CHECK-FIXES: {{^ }}if (vect3->empty()){{$}}
|
||||||
|
if ((*vect3).size() == 0)
|
||||||
|
;
|
||||||
|
// CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
|
||||||
|
// CHECK-FIXES: {{^ }}if ((*vect3).empty()){{$}}
|
||||||
|
|
||||||
delete vect3;
|
delete vect3;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue