44 ast_matchers::MatchFinder *Finder) {
46 const auto StringDecl = type(hasUnqualifiedDesugaredType(recordType(
47 hasDeclaration(cxxRecordDecl(hasName(
"::std::basic_string"))))));
48 const auto StringExpr =
49 expr(anyOf(hasType(StringDecl), hasType(qualType(pointsTo(StringDecl)))));
52 const auto StringConstructorExpr = expr(anyOf(
53 cxxConstructExpr(argumentCountIs(1),
54 hasDeclaration(cxxMethodDecl(hasName(
"basic_string")))),
55 cxxConstructExpr(argumentCountIs(2),
56 hasDeclaration(cxxMethodDecl(hasName(
"basic_string"))),
59 hasArgument(1, cxxDefaultArgExpr()))));
62 const auto StringViewConstructorExpr = cxxConstructExpr(
64 hasDeclaration(cxxMethodDecl(hasName(
"basic_string_view"))));
67 const auto StringCStrCallExpr =
68 cxxMemberCallExpr(on(StringExpr.bind(
"arg")),
69 callee(memberExpr().bind(
"member")),
70 callee(cxxMethodDecl(hasAnyName(
"c_str",
"data"))))
72 const auto HasRValueTempParent =
73 hasParent(materializeTemporaryExpr(unless(isBoundToLValue())));
81 anyOf(StringConstructorExpr, StringViewConstructorExpr),
82 hasArgument(0, StringCStrCallExpr),
83 unless(anyOf(HasRValueTempParent, hasParent(cxxBindTemporaryExpr(
84 HasRValueTempParent)))))),
90 hasAnyOverloadedOperatorName(
"<",
">",
">=",
"<=",
"!=",
"==",
"+"),
91 anyOf(allOf(hasArgument(0, StringExpr),
92 hasArgument(1, StringCStrCallExpr)),
93 allOf(hasArgument(0, StringCStrCallExpr),
94 hasArgument(1, StringExpr)))),
100 cxxOperatorCallExpr(hasAnyOverloadedOperatorName(
"=",
"+="),
101 hasArgument(0, StringExpr),
102 hasArgument(1, StringCStrCallExpr)),
107 cxxMemberCallExpr(on(StringExpr),
108 callee(decl(cxxMethodDecl(
109 hasAnyName(
"append",
"assign",
"compare")))),
110 argumentCountIs(1), hasArgument(0, StringCStrCallExpr)),
115 cxxMemberCallExpr(on(StringExpr),
116 callee(decl(cxxMethodDecl(hasName(
"compare")))),
117 argumentCountIs(3), hasArgument(2, StringCStrCallExpr)),
122 cxxMemberCallExpr(on(StringExpr),
123 callee(decl(cxxMethodDecl(hasAnyName(
124 "find",
"find_first_not_of",
"find_first_of",
125 "find_last_not_of",
"find_last_of",
"rfind")))),
126 anyOf(argumentCountIs(1), argumentCountIs(2)),
127 hasArgument(0, StringCStrCallExpr)),
132 cxxMemberCallExpr(on(StringExpr),
133 callee(decl(cxxMethodDecl(hasName(
"insert")))),
134 argumentCountIs(2), hasArgument(1, StringCStrCallExpr)),
146 hasDeclaration(cxxMethodDecl(hasAnyName(
147 "::llvm::StringRef::StringRef",
"::llvm::Twine::Twine"))),
154 hasArgument(0, StringCStrCallExpr))),
157 if (!StringParameterFunctions.empty()) {
163 StringParameterFunctions))),
164 forEachArgumentWithParam(StringCStrCallExpr,
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.