[clang] [clang] Fix crash parsing delayed lambda default arguments (PR #213556)
Gauarv Chaudhary via cfe-commits
cfe-commits at lists.llvm.org
Sun Aug 2 18:33:42 PDT 2026
https://github.com/ANAMASGARD updated https://github.com/llvm/llvm-project/pull/213556
>From 48655deecf771b2248b73a008e293beaae1478ce Mon Sep 17 00:00:00 2001
From: Gaurav Chaudhary <chaudharygaurav2004 at gmail.com>
Date: Sun, 2 Aug 2026 22:26:23 +0530
Subject: [PATCH] [clang] Fix crash during delayed default argument parsing
Signed-off-by: Gaurav Chaudhary <chaudharygaurav2004 at gmail.com>
---
clang/lib/Sema/SemaExpr.cpp | 7 +++++--
clang/test/SemaCXX/GH213420.cpp | 12 ++++++++++++
2 files changed, 17 insertions(+), 2 deletions(-)
create mode 100644 clang/test/SemaCXX/GH213420.cpp
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 59b8c9b60663c..146dd7e78a27c 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -2125,8 +2125,11 @@ static Decl *getPredefinedExprDecl(Sema &S, DeclContext *DC) {
while (LSI != E && isa<CapturingScopeInfo>(*LSI) &&
!isa<LambdaScopeInfo>(*LSI))
++LSI;
- assert(LSI != E && "Should be in a lambda scope info");
- if (dyn_cast<LambdaScopeInfo>(*LSI)->BeforeCompoundStatement)
+ if (LSI == E || !isa<LambdaScopeInfo>(*LSI)) {
+ // The lambda scope may already be popped during delayed parsing.
+ return;
+ }
+ if (cast<LambdaScopeInfo>(*LSI)->BeforeCompoundStatement)
DC = DC->getParent();
++LSI;
}
diff --git a/clang/test/SemaCXX/GH213420.cpp b/clang/test/SemaCXX/GH213420.cpp
new file mode 100644
index 0000000000000..2d1b9f032e7e4
--- /dev/null
+++ b/clang/test/SemaCXX/GH213420.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fms-compatibility -verify \
+// RUN: -Wno-missing-declarations -Wno-unused-value %s
+
+void foo() {
+ [] {
+ struct { // expected-error {{anonymous structs and classes must be class members}}
+ void bar(int & = "") {} // expected-error {{non-const lvalue reference to type 'int' cannot bind}}
+ // expected-note at -1 {{passing argument to parameter here}}
+ // expected-error at -2 {{functions cannot be declared in an anonymous struct}}
+ };
+ };
+}
More information about the cfe-commits
mailing list