[clang] [Clang] Fix error recovery for default arguments (PR #208868)

via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 10 23:50:11 PDT 2026


https://github.com/gtrong updated https://github.com/llvm/llvm-project/pull/208868

>From bea2f051f9abe168386265e9f015ceced30574fa Mon Sep 17 00:00:00 2001
From: gtrong <1619664008 at qq.com>
Date: Fri, 10 Jul 2026 21:32:11 +0800
Subject: [PATCH] Backup my fixes before forcing LF

---
 clang/lib/Parse/ParseDecl.cpp          |  5 +++--
 clang/test/Parser/cxx-default-args.cpp | 11 +++++++++++
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 3f41e7c5c6f0d..d31de39259c1a 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -7777,9 +7777,10 @@ void Parser::ParseParameterDeclarationClause(
                                                      /*DefaultArg=*/nullptr);
               // Skip the statement expression and continue parsing
               SkipUntil(tok::comma, StopBeforeMatch);
-              continue;
+              DefArgResult = ExprError();
+            } else {
+              DefArgResult = ParseAssignmentExpression();
             }
-            DefArgResult = ParseAssignmentExpression();
           }
           if (DefArgResult.isInvalid()) {
             Actions.ActOnParamDefaultArgumentError(Param, EqualLoc,
diff --git a/clang/test/Parser/cxx-default-args.cpp b/clang/test/Parser/cxx-default-args.cpp
index 0a4dbe19d8d54..31ff5822acac2 100644
--- a/clang/test/Parser/cxx-default-args.cpp
+++ b/clang/test/Parser/cxx-default-args.cpp
@@ -46,3 +46,14 @@ template <class T> void f();
 template <> void f<int>(int = []{ ; return 0; }()) {} // expected-error{{no function template matches function template specialization 'f'}} \
                                                       // expected-note at -1{{candidate template ignored}}
 }
+
+//PR208868
+struct Y {};
+enum E { e1, e2 };
+
+template<typename T>
+auto foo(E = ({ ; }) ? 0 : 1, E = e2) {  // expected-error {{default argument may not use a GNU statement expression}}
+  return 42;
+}
+
+static_assert(foo<Y>(e1) == 42, ""); // expected-error {{no matching function for call to 'foo'}}



More information about the cfe-commits mailing list