loplugin:stringconcat: Handle base case of recursion into left arg

Change-Id: I9ed8586e8b77b009d55e411fdaa863eefc38b1c2
This commit is contained in:
Stephan Bergmann
2015-12-02 11:38:07 +01:00
parent a38110216c
commit f540e9264c

View File

@@ -39,22 +39,28 @@ bool StringConcat::VisitCallExpr(CallExpr const * expr) {
{ {
return true; return true;
} }
CallExpr const * left = dyn_cast<CallExpr>( SourceLocation leftLoc;
expr->getArg(0)->IgnoreParenImpCasts()); auto const leftExpr = expr->getArg(0)->IgnoreParenImpCasts();
if (left == nullptr) { if (isa<StringLiteral>(leftExpr)) {
return true; leftLoc = leftExpr->getLocStart();
} } else {
FunctionDecl const * ldecl = left->getDirectCallee(); CallExpr const * left = dyn_cast<CallExpr>(leftExpr);
if (ldecl == nullptr) { if (left == nullptr) {
return true; return true;
} }
OverloadedOperatorKind loo = ldecl->getOverloadedOperator(); FunctionDecl const * ldecl = left->getDirectCallee();
if ((loo != OverloadedOperatorKind::OO_Plus if (ldecl == nullptr) {
&& loo != OverloadedOperatorKind::OO_LessLess) return true;
|| ldecl->getNumParams() != 2 || left->getNumArgs() != 2 }
|| !isa<StringLiteral>(left->getArg(1)->IgnoreParenImpCasts())) OverloadedOperatorKind loo = ldecl->getOverloadedOperator();
{ if ((loo != OverloadedOperatorKind::OO_Plus
return true; && 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 { StringRef name {
compiler.getSourceManager().getFilename( compiler.getSourceManager().getFilename(
@@ -70,8 +76,7 @@ bool StringConcat::VisitCallExpr(CallExpr const * expr) {
"replace '%0' between string literals with juxtaposition", "replace '%0' between string literals with juxtaposition",
op == nullptr ? expr->getExprLoc() : op->getOperatorLoc()) op == nullptr ? expr->getExprLoc() : op->getOperatorLoc())
<< (oo == OverloadedOperatorKind::OO_Plus ? "+" : "<<") << (oo == OverloadedOperatorKind::OO_Plus ? "+" : "<<")
<< SourceRange( << SourceRange(leftLoc, expr->getArg(1)->getLocEnd());
left->getArg(1)->getLocStart(), expr->getArg(1)->getLocEnd());
return true; return true;
} }