[clang] Don't mark lambda non-dependent if nested in a generic lambda. (PR #149121)
Younan Zhang via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 16 09:06:06 PDT 2025
================
@@ -15512,6 +15512,8 @@ TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
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()))
----------------
zyn0217 wrote:
So if I understand correctly, the inner generic lambda was previously caught by `!DC->getParent()->isDependentContext()` because its parent, despite it being a generic, is living in a non-dependent context such that the parent is never dependent which entails !isDependentContext()?
I am not quite sure if the approach is correct because the semantic of the dependency kind for lambda is sometimes counter-intuitive. For example, we even consider a generic lambda non-dependent if it lives in e.g. a namespace scope.
On the other hand, if the outer lambda (assuming it is generic) gets instantiated, then the 'generic' flag on it is still preserved, see `TransformTemplateParameterList()` in this function below and `CompleteLambdaCallOperator`, so at the time when the nested lambdas are half-transformed, the inner dependency kind might still be unexpected.
@mizvekov has been working on the removal of the DependencyKind and he might have some ideas too.
https://github.com/llvm/llvm-project/pull/149121
More information about the cfe-commits
mailing list