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

via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 5 09:56:40 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();
----------------
cor3ntin wrote:

ideally yes, I'd assert on it... but we do not have access to that information in constant evaluation

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


More information about the cfe-commits mailing list