Skip to content

Commit ca39496

Browse files
zyn0217llvmbot
authored andcommitted
[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 #136254 No release entry because I want to backport it. (cherry picked from commit c7daab2)
1 parent ab0074f commit ca39496

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

clang/lib/Parse/ParseExpr.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -2237,8 +2237,6 @@ Parser::ParsePostfixExpressionSuffix(ExprResult LHS) {
22372237
if (PP.isCodeCompletionReached() && !CalledSignatureHelp)
22382238
RunSignatureHelp();
22392239
LHS = ExprError();
2240-
} else if (!HasError && HasTrailingComma) {
2241-
Diag(Tok, diag::err_expected_expression);
22422240
} else if (LHS.isInvalid()) {
22432241
for (auto &E : ArgExprs)
22442242
Actions.CorrectDelayedTyposInExpr(E);
@@ -3738,7 +3736,6 @@ bool Parser::ParseExpressionList(SmallVectorImpl<Expr *> &Exprs,
37383736
if (Tok.is(tok::r_paren)) {
37393737
if (HasTrailingComma)
37403738
*HasTrailingComma = true;
3741-
break;
37423739
}
37433740
}
37443741
if (SawError) {

clang/test/Parser/recovery.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -222,3 +222,21 @@ void k() {
222222
func(1, ); // expected-error {{expected expression}}
223223
}
224224
}
225+
226+
namespace GH136254 {
227+
228+
void call() {
229+
[a(42, )]() {} (); // expected-error {{expected expression}}
230+
231+
int *b = new int(42, ); // expected-error {{expected expression}}
232+
233+
struct S {
234+
int c;
235+
236+
S() : c(42, ) {} // expected-error {{expected expression}}
237+
};
238+
239+
int d(42, ); // expected-error {{expected expression}}
240+
}
241+
242+
}

0 commit comments

Comments
 (0)