[clang] [Clang] Keep lambdas in default template arguments dependent until used (PR #222541)
Younan Zhang via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 11 03:58:03 PDT 2026
================
@@ -16304,11 +16308,13 @@ TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
// (A ClassTemplateSpecializationDecl is always a dependent context.)
while (DC->isRequiresExprBody() || isa<CXXExpansionStmtDecl>(DC))
DC = DC->getParent();
- if ((getSema().isUnevaluatedContext() ||
- getSema().isConstantEvaluatedContext()) &&
- !(dyn_cast_or_null<CXXRecordDecl>(DC->getParent()) &&
- cast<CXXRecordDecl>(DC->getParent())->isGenericLambda()) &&
- (DC->isFileContext() || !DC->getParent()->isDependentContext()))
+ if (getDerived().IsLambdaAlwaysDependent())
+ DependencyKind = CXXRecordDecl::LDK_AlwaysDependent;
----------------
zyn0217 wrote:
So I suggest you as a human really think about this issue, not simply ask your agents design/generate and pretend it's working.
To demonstrate what I meant, here is an example which is rejected by clang 16:
```cpp
template <class>
concept C = false;
template <int> struct bad {
template <auto = []<C... U>(U...) { return 42; }(1, 2)>
struct X {};
};
bad<1>::X x;
```
and with this PR, yes it stops crashing, but it also caused to accept invalid code.
https://github.com/llvm/llvm-project/pull/222541
More information about the cfe-commits
mailing list