[clang] [webkit.UncountedLambdaCapturesChecker] Ignore a lambda which gets called immediately (PR #162977)

Balázs Benics via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 18 03:33:23 PST 2025


================
@@ -253,6 +253,17 @@ class RawPtrRefLambdaCapturesChecker
         auto *Callee = CE->getCallee();
         if (!Callee)
           return;
+        Callee = Callee->IgnoreParenCasts();
+        if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(Callee)) {
+          Callee = MTE->getSubExpr();
+          if (!Callee)
+            return;
+          Callee = Callee->IgnoreParenCasts();
+        }
+        if (auto *L = dyn_cast_or_null<LambdaExpr>(Callee)) {
----------------
steakhal wrote:

I think `Callee` cannot be null here because:
 - Callee was checked against null once we acquired it from `getCallee()`
 - `IgnoreParenCasts` always returns non null.

```suggestion
        if (auto *L = dyn_cast<LambdaExpr>(Callee)) {
```

Also by judging the density of the `dyn_casts`, I wonder if we should have chosen a `StmtVisitor` to mimic the pattern matching ad-hoc implemented here. No actions expected with this point, I'm just curious if it was considered.

https://github.com/llvm/llvm-project/pull/162977


More information about the cfe-commits mailing list