40 ast_matchers::MatchFinder *Finder) {
42 const auto StringDecl = type(hasUnqualifiedDesugaredType(recordType(
43 hasDeclaration(cxxRecordDecl(hasName(
"::std::basic_string"))))));
44 const auto StringExpr =
45 expr(anyOf(hasType(StringDecl), hasType(qualType(pointsTo(StringDecl)))));
48 const auto StringConstructorExpr = expr(anyOf(
49 cxxConstructExpr(argumentCountIs(1),
50 hasDeclaration(cxxMethodDecl(hasName(
"basic_string")))),
51 cxxConstructExpr(argumentCountIs(2),
52 hasDeclaration(cxxMethodDecl(hasName(
"basic_string"))),
55 hasArgument(1, cxxDefaultArgExpr()))));
58 const auto StringViewConstructorExpr = cxxConstructExpr(
60 hasDeclaration(cxxMethodDecl(hasName(
"basic_string_view"))));
63 const auto StringCStrCallExpr =
64 cxxMemberCallExpr(on(StringExpr.bind(
"arg")),
65 callee(memberExpr().bind(
"member")),
66 callee(cxxMethodDecl(hasAnyName(
"c_str",
"data"))))
68 const auto HasRValueTempParent =
69 hasParent(materializeTemporaryExpr(unless(isBoundToLValue())));
77 anyOf(StringConstructorExpr, StringViewConstructorExpr),
78 hasArgument(0, StringCStrCallExpr),
79 unless(anyOf(HasRValueTempParent, hasParent(cxxBindTemporaryExpr(
80 HasRValueTempParent)))))),
86 hasAnyOverloadedOperatorName(
"<",
">",
">=",
"<=",
"!=",
"==",
"+"),
87 anyOf(allOf(hasArgument(0, StringExpr),
88 hasArgument(1, StringCStrCallExpr)),
89 allOf(hasArgument(0, StringCStrCallExpr),
90 hasArgument(1, StringExpr)))),
96 cxxOperatorCallExpr(hasAnyOverloadedOperatorName(
"=",
"+="),
97 hasArgument(0, StringExpr),
98 hasArgument(1, StringCStrCallExpr)),
103 cxxMemberCallExpr(on(StringExpr),
104 callee(decl(cxxMethodDecl(
105 hasAnyName(
"append",
"assign",
"compare")))),
106 argumentCountIs(1), hasArgument(0, StringCStrCallExpr)),
111 cxxMemberCallExpr(on(StringExpr),
112 callee(decl(cxxMethodDecl(hasName(
"compare")))),
113 argumentCountIs(3), hasArgument(2, StringCStrCallExpr)),
118 cxxMemberCallExpr(on(StringExpr),
119 callee(decl(cxxMethodDecl(hasAnyName(
120 "find",
"find_first_not_of",
"find_first_of",
121 "find_last_not_of",
"find_last_of",
"rfind")))),
122 anyOf(argumentCountIs(1), argumentCountIs(2)),
123 hasArgument(0, StringCStrCallExpr)),
128 cxxMemberCallExpr(on(StringExpr),
129 callee(decl(cxxMethodDecl(hasName(
"insert")))),
130 argumentCountIs(2), hasArgument(1, StringCStrCallExpr)),
142 hasDeclaration(cxxMethodDecl(hasAnyName(
143 "::llvm::StringRef::StringRef",
"::llvm::Twine::Twine"))),
150 hasArgument(0, StringCStrCallExpr))),
153 if (!StringParameterFunctions.empty()) {
159 StringParameterFunctions))),
160 forEachArgumentWithParam(StringCStrCallExpr,
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.