43 const auto StrCat = functionDecl(hasName(
"::absl::StrCat"));
46 const auto AlphaNum = ignoringTemporaries(cxxConstructExpr(
47 argumentCountIs(1), hasType(cxxRecordDecl(hasName(
"::absl::AlphaNum"))),
48 hasArgument(0, ignoringImpCasts(declRefExpr(to(equalsBoundNode(
"LHS")),
49 expr().bind(
"Arg0"))))));
51 const auto HasAnotherReferenceToLhs =
52 callExpr(hasAnyArgument(expr(hasDescendant(declRefExpr(
53 to(equalsBoundNode(
"LHS")), unless(equalsBoundNode(
"Arg0")))))));
61 unless(isInTemplateInstantiation()),
62 hasOverloadedOperatorName(
"="),
63 hasArgument(0, declRefExpr(to(decl().bind(
"LHS")))),
65 1, ignoringTemporaries(
66 callExpr(callee(StrCat), hasArgument(0, AlphaNum),
67 unless(HasAnotherReferenceToLhs))
74 const auto *Op = Result.Nodes.getNodeAs<CXXOperatorCallExpr>(
"Op");
75 const auto *Call = Result.Nodes.getNodeAs<CallExpr>(
"Call");
76 assert(Op && Call &&
"Matcher does not work as expected");
79 if (Call->getNumArgs() == 1) {
80 diag(Op->getBeginLoc(),
"call to 'absl::StrCat' has no effect");
88 diag(Op->getBeginLoc(),
89 "call 'absl::StrAppend' instead of 'absl::StrCat' when appending to a "
90 "string to avoid a performance penalty")
91 << FixItHint::CreateReplacement(
92 CharSourceRange::getTokenRange(Op->getBeginLoc(),
93 Call->getCallee()->getEndLoc()),
95 << FixItHint::CreateInsertion(Call->getArg(0)->getBeginLoc(),
"&");