[llvm-branch-commits] [clang] aecbb23 - [Clang] Fix the trailing comma regression (#136273)
Tom Stellard via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Fri May 9 13:09:11 PDT 2025
Author: Younan Zhang
Date: 2025-05-09T13:00:44-07:00
New Revision: aecbb2364a7ccee1048447127fdb5865f70b3c6b
URL: https://github.com/llvm/llvm-project/commit/aecbb2364a7ccee1048447127fdb5865f70b3c6b
DIFF: https://github.com/llvm/llvm-project/commit/aecbb2364a7ccee1048447127fdb5865f70b3c6b.diff
LOG: [Clang] Fix the trailing comma regression (#136273)
925e195 introduced a regression since which we started to accept invalid
trailing commas in many expression lists where they're not allowed by
the grammar. The issue came from the fact that an additional invalid
state - previously handled by ParseExpressionList - was overlooked in
that patch.
Fixes https://github.com/llvm/llvm-project/issues/136254
No release entry because I want to backport it.
(cherry picked from commit c7daab259c3281cf8f649583993bad2536febc02)
Added:
Modified:
clang/lib/Parse/ParseExpr.cpp
clang/test/Parser/recovery.cpp
Removed:
################################################################################
diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index 0cadede51a9b3..2fab1dfed4a00 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -2237,8 +2237,6 @@ Parser::ParsePostfixExpressionSuffix(ExprResult LHS) {
if (PP.isCodeCompletionReached() && !CalledSignatureHelp)
RunSignatureHelp();
LHS = ExprError();
- } else if (!HasError && HasTrailingComma) {
- Diag(Tok, diag::err_expected_expression);
} else if (LHS.isInvalid()) {
for (auto &E : ArgExprs)
Actions.CorrectDelayedTyposInExpr(E);
@@ -3738,7 +3736,6 @@ bool Parser::ParseExpressionList(SmallVectorImpl<Expr *> &Exprs,
if (Tok.is(tok::r_paren)) {
if (HasTrailingComma)
*HasTrailingComma = true;
- break;
}
}
if (SawError) {
diff --git a/clang/test/Parser/recovery.cpp b/clang/test/Parser/recovery.cpp
index 2fce67a52c6b6..261f5dc99bad4 100644
--- a/clang/test/Parser/recovery.cpp
+++ b/clang/test/Parser/recovery.cpp
@@ -222,3 +222,21 @@ void k() {
func(1, ); // expected-error {{expected expression}}
}
}
+
+namespace GH136254 {
+
+void call() {
+ [a(42, )]() {} (); // expected-error {{expected expression}}
+
+ int *b = new int(42, ); // expected-error {{expected expression}}
+
+ struct S {
+ int c;
+
+ S() : c(42, ) {} // expected-error {{expected expression}}
+ };
+
+ int d(42, ); // expected-error {{expected expression}}
+}
+
+}
More information about the llvm-branch-commits
mailing list