aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/AST/ComputeDependence.cpp
diff options
context:
space:
mode:
authorSirraide <aeternalmail@gmail.com>2024-04-09 14:52:52 +0200
committerGitHub <noreply@github.com>2024-04-09 14:52:52 +0200
commit38824f285f1459cb890337d2df1a3cafd3fd109d (patch)
tree5a59762a708e65c906806e10623809ac95ca9b14 /clang/lib/AST/ComputeDependence.cpp
parenta4cf479cdf08093b69177dd9adf32eebf3632dc3 (diff)
downloadllvm-38824f285f1459cb890337d2df1a3cafd3fd109d.zip
llvm-38824f285f1459cb890337d2df1a3cafd3fd109d.tar.gz
llvm-38824f285f1459cb890337d2df1a3cafd3fd109d.tar.bz2
[Clang] [Sema] Fix dependence of DREs in lambdas with an explicit object parameter (#84473)
This fixes some problems wrt dependence of captures in lambdas with an explicit object parameter. [temp.dep.expr] states that > An id-expression is type-dependent if [...] its terminal name is > - associated by name lookup with an entity captured by copy > ([expr.prim.lambda.capture]) in a lambda-expression that has > an explicit object parameter whose type is dependent [dcl.fct]. There were several issues with our implementation of this: 1. we were treating by-reference captures as dependent rather than by-value captures; 2. tree transform wasn't checking whether referring to such a by-value capture should make a DRE dependent; 3. when checking whether a DRE refers to such a by-value capture, we were only looking at the immediately enclosing lambda, and not at any parent lambdas; 4. we also forgot to check for implicit by-value captures; 5. lastly, we were attempting to determine whether a lambda has an explicit object parameter by checking the `LambdaScopeInfo`'s `ExplicitObjectParameter`, but it seems that that simply wasn't set (yet) by the time we got to the check. All of these should be fixed now. This fixes #70604, #79754, #84163, #84425, #86054, #86398, and #86399.
Diffstat (limited to 'clang/lib/AST/ComputeDependence.cpp')
-rw-r--r--clang/lib/AST/ComputeDependence.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/clang/lib/AST/ComputeDependence.cpp b/clang/lib/AST/ComputeDependence.cpp
index 86b77b4..5ec3013 100644
--- a/clang/lib/AST/ComputeDependence.cpp
+++ b/clang/lib/AST/ComputeDependence.cpp
@@ -310,6 +310,16 @@ ExprDependence clang::computeDependence(CXXThisExpr *E) {
// 'this' is type-dependent if the class type of the enclosing
// member function is dependent (C++ [temp.dep.expr]p2)
auto D = toExprDependenceForImpliedType(E->getType()->getDependence());
+
+ // If a lambda with an explicit object parameter captures '*this', then
+ // 'this' now refers to the captured copy of lambda, and if the lambda
+ // is type-dependent, so is the object and thus 'this'.
+ //
+ // Note: The standard does not mention this case explicitly, but we need
+ // to do this so we can mark NSDM accesses as dependent.
+ if (E->isCapturedByCopyInLambdaWithExplicitObjectParameter())
+ D |= ExprDependence::Type;
+
assert(!(D & ExprDependence::UnexpandedPack));
return D;
}