[clang] [Clang] prevent assertion failure by avoiding always-dependent lambdas in constraint-related nested scopes (PR #173776)

Oleksandr T. via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 2 03:54:02 PST 2026


================
@@ -1113,10 +1113,14 @@ void Sema::ActOnLambdaExpressionAfterIntroducer(LambdaIntroducer &Intro,
     // The parameter var is not injected into the function Decl at the point of
     // parsing lambda. In such scenarios, perceiving it as dependent could
     // result in the constraint being evaluated, which matches what GCC does.
-    while (P->getEntity() && P->getEntity()->isRequiresExprBody())
-      P = P->getParent();
-    if (P->isFunctionDeclarationScope() &&
-        llvm::any_of(P->decls(), [](Decl *D) {
+    Scope *LookupScope = ParentScope;
+    while (LookupScope->getEntity() &&
+           LookupScope->getEntity()->isRequiresExprBody())
----------------
a-tarasyuk wrote:

@cor3ntin, thanks for the feedback. 

There’s an existing pattern around `isTransparentContext`, however, I haven’t found similar duplicated handling for `isRequiresExprBody`. I thought about moving this walk-up logic into a helper that accepts a callback, like

```cpp
findNearestEntityScope(Scope *S, llvm::function_ref<bool(const DeclContext &)> Predicate) {
  while (S && S->getEntity() && Predicate(*S->getEntity()))
    S = S->getParent();
  return S;
}
....
```

I’m unsure whether this is a good fit for a new helper. WDYT?


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


More information about the cfe-commits mailing list