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(
|
||||
cxxMemberCallExpr(on(expr(anyOf(hasType(ValidContainer),
|
||||
hasType(pointsTo(ValidContainer)),
|
||||
hasType(references(ValidContainer))))
|
||||
.bind("STLObject")),
|
||||
hasType(references(ValidContainer))))),
|
||||
callee(cxxMethodDecl(hasName("size"))), WrongUse,
|
||||
unless(hasAncestor(cxxMethodDecl(
|
||||
ofClass(equalsBoundNode("container"))))))
|
||||
|
@ -69,7 +68,7 @@ void ContainerSizeEmptyCheck::check(const MatchFinder::MatchResult &Result) {
|
|||
const auto *MemberCall =
|
||||
Result.Nodes.getNodeAs<CXXMemberCallExpr>("SizeCallExpr");
|
||||
const auto *BinaryOp = Result.Nodes.getNodeAs<BinaryOperator>("SizeBinaryOp");
|
||||
const auto *E = Result.Nodes.getNodeAs<Expr>("STLObject");
|
||||
const auto *E = MemberCall->getImplicitObjectArgument();
|
||||
FixItHint Hint;
|
||||
std::string ReplacementText =
|
||||
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-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;
|
||||
|
||||
|
|
Loading…
Reference in New Issue