Skip to content

Commit c7daab2

Browse files
authored
[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.
1 parent 64ffecf commit c7daab2

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
@@ -2239,8 +2239,6 @@ Parser::ParsePostfixExpressionSuffix(ExprResult LHS) {
22392239
if (PP.isCodeCompletionReached() && !CalledSignatureHelp)
22402240
RunSignatureHelp();
22412241
LHS = ExprError();
2242-
} else if (!HasError && HasTrailingComma) {
2243-
Diag(Tok, diag::err_expected_expression);
22442242
} else if (LHS.isInvalid()) {
22452243
for (auto &E : ArgExprs)
22462244
Actions.CorrectDelayedTyposInExpr(E);
@@ -3750,7 +3748,6 @@ bool Parser::ParseExpressionList(SmallVectorImpl<Expr *> &Exprs,
37503748
if (Tok.is(tok::r_paren)) {
37513749
if (HasTrailingComma)
37523750
*HasTrailingComma = true;
3753-
break;
37543751
}
37553752
}
37563753
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)