@@ -122,21 +122,19 @@ void CapturingThisInMemberVariableCheck::registerMatchers(MatchFinder *Finder) {
122122}
123123void CapturingThisInMemberVariableCheck::check (
124124 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-
134125 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" );
136130 } else if (const auto *Bind = Result.Nodes .getNodeAs <CallExpr>(" bind" )) {
137131 const auto *Callee = Result.Nodes .getNodeAs <FunctionDecl>(" callee" );
138132 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 ();
140138 }
141139
142140 const auto *Field = Result.Nodes .getNodeAs <FieldDecl>(" field" );
0 commit comments