[clang] [Clang] Fix crash with `source_location` in lambda declarators. (PR #107411)

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 5 08:03:01 PDT 2024


================
@@ -2287,6 +2288,15 @@ APValue SourceLocExpr::EvaluateInContext(const ASTContext &Ctx,
     Context = getParentContext();
   }
 
+  // If we are currently parsing a lambda declarator, we might not have a fully
+  // formed call operator declaration yet, and we could not form a function name
+  // for it. Because we do not have access to Sema/function scopes here, we
+  // detect this case by relying on the fact such method doesn't yet have a
+  // type.
+  if (const auto *D = dyn_cast<CXXMethodDecl>(Context);
+      D && D->getFunctionTypeLoc().isNull() && isLambdaCallOperator(D))
+    Context = D->getParent()->getParent();
----------------
erichkeane wrote:

So the first `getParent` should get the lambda object, correct?  

Could this cause issues where the parent of the lambda is a TU?  Can we have a test for that?  Also, there are some goofinesses around variable templates and requires in a lambda, can we have a test for that?

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


More information about the cfe-commits mailing list