@@ -122,21 +122,19 @@ void CapturingThisInMemberVariableCheck::registerMatchers(MatchFinder *Finder) {
122
122
}
123
123
void CapturingThisInMemberVariableCheck::check (
124
124
const MatchFinder::MatchResult &Result) {
125
- const auto EmitDiag = [this ](const SourceLocation &Location,
126
- const FunctionDecl *Bind) {
127
- const std::string BindName = Bind ? Bind->getQualifiedNameAsString () : " " ;
128
- diag (Location, " 'this' captured by a %select{lambda|'%1' call}0 and "
129
- " stored in a class member variable; disable implicit class "
130
- " copying/moving to prevent potential use-after-free" )
131
- << (Bind ? 1 : 0 ) << BindName;
132
- };
133
-
134
125
if (const auto *Lambda = Result.Nodes .getNodeAs <LambdaExpr>(" lambda" )) {
135
- EmitDiag (Lambda->getBeginLoc (), nullptr );
126
+ diag (Lambda->getBeginLoc (),
127
+ " 'this' captured by a lambda and stored in a class member variable; "
128
+ " disable implicit class copying/moving to prevent potential "
129
+ " use-after-free" );
136
130
} else if (const auto *Bind = Result.Nodes .getNodeAs <CallExpr>(" bind" )) {
137
131
const auto *Callee = Result.Nodes .getNodeAs <FunctionDecl>(" callee" );
138
132
assert (Callee);
139
- EmitDiag (Bind->getBeginLoc (), Callee);
133
+ diag (Bind->getBeginLoc (),
134
+ " 'this' captured by a '%0' call and stored in a class member "
135
+ " variable; disable implicit class copying/moving to prevent potential "
136
+ " use-after-free" )
137
+ << Callee->getQualifiedNameAsString ();
140
138
}
141
139
142
140
const auto *Field = Result.Nodes .getNodeAs <FieldDecl>(" field" );
0 commit comments