[clang-tools-extra] [clang-tidy] Add `AllowExplicitObjectParameters` option to `avoid-capturing-lambda-coroutines` (PR #182916)
Willem Kaufmann via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 3 05:20:48 PDT 2026
================
@@ -21,19 +21,40 @@ AST_MATCHER(LambdaExpr, hasCoroutineBody) {
}
AST_MATCHER(LambdaExpr, hasCaptures) { return Node.capture_size() != 0U; }
+
+AST_MATCHER(LambdaExpr, hasDeducingThis) {
+ return Node.getCallOperator()->isExplicitObjectMemberFunction();
+}
} // namespace
+AvoidCapturingLambdaCoroutinesCheck::AvoidCapturingLambdaCoroutinesCheck(
+ StringRef Name, ClangTidyContext *Context)
+ : ClangTidyCheck(Name, Context),
+ AllowExplicitObjectParameters(
+ Options.get("AllowExplicitObjectParameters", false)) {}
+
void AvoidCapturingLambdaCoroutinesCheck::registerMatchers(
MatchFinder *Finder) {
- Finder->addMatcher(
- lambdaExpr(hasCaptures(), hasCoroutineBody()).bind("lambda"), this);
+ auto Matcher = lambdaExpr(hasCaptures(), hasCoroutineBody());
+
+ if (AllowExplicitObjectParameters)
+ Matcher = lambdaExpr(hasCaptures(), hasCoroutineBody(),
+ unless(hasDeducingThis()));
----------------
WillemKauf wrote:
Reworked the matcher in this spirit (your impl had some bugs but hopefully you find the way I wrote it agreeable)
https://github.com/llvm/llvm-project/pull/182916
More information about the cfe-commits
mailing list