https://github.com/kadircet created 
https://github.com/llvm/llvm-project/pull/175582

Fixes #173662 

From 6ae6b1996447372daa7152c8713623c8e519aa26 Mon Sep 17 00:00:00 2001
From: Kadir Cetinkaya <[email protected]>
Date: Mon, 12 Jan 2026 16:53:54 +0100
Subject: [PATCH] [clang][Sema] Early exit when default arg contains errors

---
 clang/lib/Sema/SemaTemplateInstantiate.cpp       | 5 +++++
 clang/test/Sema/inst-with-broken-default-arg.cpp | 6 ++++++
 2 files changed, 11 insertions(+)
 create mode 100644 clang/test/Sema/inst-with-broken-default-arg.cpp

diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 35205f40cbcef..5577671786d39 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -3190,6 +3190,11 @@ bool Sema::SubstDefaultArgument(
            << FD << PatternExpr->getSourceRange();
   }
 
+  // Exit early if argument has error, we should've emitted the diagnostic when
+  // we constructed the default arg expr.
+  if (PatternExpr->containsErrors())
+    return true;
+
   EnterExpressionEvaluationContext EvalContext(
       *this, ExpressionEvaluationContext::PotentiallyEvaluated, Param);
   NonSFINAEContext _(*this);
diff --git a/clang/test/Sema/inst-with-broken-default-arg.cpp 
b/clang/test/Sema/inst-with-broken-default-arg.cpp
new file mode 100644
index 0000000000000..6b0794e73458b
--- /dev/null
+++ b/clang/test/Sema/inst-with-broken-default-arg.cpp
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 %s -verify
+// We expect this test to emit a diagnostic, but not crash.
+void foo() {
+  auto inner_y = [z = 0](auto inner_y, double inner_val = z) {}; // 
expected-error {{}}
+  inner_y(0);
+}

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

Reply via email to