Skip to content

Commit 5ecb2de

Browse files
committed
Diagnose the code with trailing comma in the function call.
1 parent ae30383 commit 5ecb2de

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

clang/include/clang/Basic/DiagnosticParseKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,8 @@ def ext_consteval_if : ExtWarn<
703703
def warn_cxx20_compat_consteval_if : Warning<
704704
"consteval if is incompatible with C++ standards before C++23">,
705705
InGroup<CXXPre23Compat>, DefaultIgnore;
706+
def err_extraneous_trailing_comma : Error<
707+
"extraneous trailing comma">;
706708

707709
def ext_init_statement : ExtWarn<
708710
"'%select{if|switch}0' initialization statements are a C++17 extension">,

clang/lib/Parse/ParseExpr.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2237,6 +2237,9 @@ Parser::ParsePostfixExpressionSuffix(ExprResult LHS) {
22372237
if (PP.isCodeCompletionReached() && !CalledSignatureHelp)
22382238
RunSignatureHelp();
22392239
LHS = ExprError();
2240+
} else if (!HasError && HasTrailingComma) {
2241+
// FIXME: add a FIXIT to remove the trailing comma.
2242+
Diag(Tok, diag::err_extraneous_trailing_comma);
22402243
} else if (LHS.isInvalid()) {
22412244
for (auto &E : ArgExprs)
22422245
Actions.CorrectDelayedTyposInExpr(E);

clang/test/Parser/recovery.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,3 +215,10 @@ struct ::template foo, struct ::template bar; // expected-error 2 {{expected ide
215215
struct ::foo struct::; // expected-error {{no struct named 'foo' in the global namespace}} expected-error {{expected identifier}}
216216
class :: : {} a; // expected-error {{expected identifier}} expected-error {{expected class name}}
217217
}
218+
219+
namespace GH125225 {
220+
void func(int);
221+
void k() {
222+
func(1, ); // expected-error {{extraneous trailing comma}}
223+
}
224+
}

0 commit comments

Comments
 (0)