From f540e9264ccb096312cfa8972eb58c94238086a6 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Wed, 2 Dec 2015 11:38:07 +0100 Subject: [PATCH] loplugin:stringconcat: Handle base case of recursion into left arg Change-Id: I9ed8586e8b77b009d55e411fdaa863eefc38b1c2 --- compilerplugins/clang/stringconcat.cxx | 41 +++++++++++++++----------- 1 file 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( - 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(left->getArg(1)->IgnoreParenImpCasts())) - { - return true; + SourceLocation leftLoc; + auto const leftExpr = expr->getArg(0)->IgnoreParenImpCasts(); + if (isa(leftExpr)) { + leftLoc = leftExpr->getLocStart(); + } else { + CallExpr const * left = dyn_cast(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(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; }