diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2015-12-02 11:38:07 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2015-12-02 14:01:55 +0100 |
commit | f540e9264ccb096312cfa8972eb58c94238086a6 (patch) | |
tree | 92362648a9a8b37c8132670fcfd1a2a632a4121f | |
parent | a38110216c895e876ab1b4697da74f559d06a3cb (diff) |
loplugin:stringconcat: Handle base case of recursion into left arg
Change-Id: I9ed8586e8b77b009d55e411fdaa863eefc38b1c2
-rw-r--r-- | compilerplugins/clang/stringconcat.cxx | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/compilerplugins/clang/stringconcat.cxx b/compilerplugins/clang/stringconcat.cxx index 43907e927cb3..cd33bab126ac 100644 --- a/compilerplugins/clang/stringconcat.cxx +++ b/compilerplugins/clang/stringconcat.cxx @@ -39,22 +39,28 @@ bool StringConcat::VisitCallExpr(CallExpr const * expr) { { return true; } - CallExpr const * left = dyn_cast<CallExpr>( - expr->getArg(0)->IgnoreParenImpCasts()); - if (left == nullptr) { - return true; - } - FunctionDecl const * ldecl = left->getDirectCallee(); - if (ldecl == nullptr) { - return true; - } - OverloadedOperatorKind loo = ldecl->getOverloadedOperator(); - if ((loo != OverloadedOperatorKind::OO_Plus - && loo != OverloadedOperatorKind::OO_LessLess) - || ldecl->getNumParams() != 2 || left->getNumArgs() != 2 - || !isa<StringLiteral>(left->getArg(1)->IgnoreParenImpCasts())) - { - return true; + SourceLocation leftLoc; + auto const leftExpr = expr->getArg(0)->IgnoreParenImpCasts(); + if (isa<StringLiteral>(leftExpr)) { + leftLoc = leftExpr->getLocStart(); + } else { + CallExpr const * left = dyn_cast<CallExpr>(leftExpr); + if (left == nullptr) { + return true; + } + FunctionDecl const * ldecl = left->getDirectCallee(); + if (ldecl == nullptr) { + return true; + } + OverloadedOperatorKind loo = ldecl->getOverloadedOperator(); + if ((loo != OverloadedOperatorKind::OO_Plus + && loo != OverloadedOperatorKind::OO_LessLess) + || ldecl->getNumParams() != 2 || left->getNumArgs() != 2 + || !isa<StringLiteral>(left->getArg(1)->IgnoreParenImpCasts())) + { + return true; + } + leftLoc = left->getArg(1)->getLocStart(); } StringRef name { compiler.getSourceManager().getFilename( @@ -70,8 +76,7 @@ bool StringConcat::VisitCallExpr(CallExpr const * expr) { "replace '%0' between string literals with juxtaposition", op == nullptr ? expr->getExprLoc() : op->getOperatorLoc()) << (oo == OverloadedOperatorKind::OO_Plus ? "+" : "<<") - << SourceRange( - left->getArg(1)->getLocStart(), expr->getArg(1)->getLocEnd()); + << SourceRange(leftLoc, expr->getArg(1)->getLocEnd()); return true; } |