https://github.com/ANAMASGARD created 
https://github.com/llvm/llvm-project/pull/213556


  Closes #213420.

  This fixes a crash with `-fms-compatibility` when Clang late-parses an 
invalid default argument in a member function of a lambda-local anonymous 
struct.

  `getPredefinedExprDecl` assumed an active `LambdaScopeInfo` was always 
present. During delayed parsing, that scope may already have been popped. 
Handle that case and continue producing the normal diagnostics.

  Tests:
  - `llvm-lit -sv clang/test/SemaCXX/GH213420.cpp`
  - `llvm-lit -sv clang/test/SemaCXX` (no unexpected failures)
  - Manual assertion-enabled reproducer: no crash; emits the expected semantic 
errors
  - `git diff --check`

  AI assistance was used to investigate, implement, and test this change. I  
reviewed the resulting patch and test coverage.

>From 48655deecf771b2248b73a008e293beaae1478ce Mon Sep 17 00:00:00 2001
From: Gaurav Chaudhary <[email protected]>
Date: Sun, 2 Aug 2026 22:26:23 +0530
Subject: [PATCH] [clang] Fix crash during delayed default argument parsing

Signed-off-by: Gaurav Chaudhary <[email protected]>
---
 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@-1 {{passing argument to 
parameter here}}
+                              // expected-error@-2 {{functions cannot be 
declared in an anonymous struct}}
+    };
+  };
+}

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to