[clang] 922f339 - Diagnose the code with trailing comma in the function call. (#125232)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 14 07:21:57 PST 2025
Author: Haojian Wu
Date: 2025-02-14T16:21:53+01:00
New Revision: 922f339c4ef3631f66dc4b8caa4c356103dbf69d
URL: https://github.com/llvm/llvm-project/commit/922f339c4ef3631f66dc4b8caa4c356103dbf69d
DIFF: https://github.com/llvm/llvm-project/commit/922f339c4ef3631f66dc4b8caa4c356103dbf69d.diff
LOG: Diagnose the code with trailing comma in the function call. (#125232)
This patch fixes a regression caused by
https://github.com/llvm/llvm-project/pull/114684 where clang accepts
trailing commas for function calls.
Fixes #125225
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 da5f2ccf3a0c6..0c28972d6ed8f 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -2236,6 +2236,8 @@ 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);
diff --git a/clang/test/Parser/recovery.cpp b/clang/test/Parser/recovery.cpp
index 4e2811c4cac92..2fce67a52c6b6 100644
--- a/clang/test/Parser/recovery.cpp
+++ b/clang/test/Parser/recovery.cpp
@@ -215,3 +215,10 @@ struct ::template foo, struct ::template bar; // expected-error 2 {{expected ide
struct ::foo struct::; // expected-error {{no struct named 'foo' in the global namespace}} expected-error {{expected identifier}}
class :: : {} a; // expected-error {{expected identifier}} expected-error {{expected class name}}
}
+
+namespace GH125225 {
+void func(int);
+void k() {
+ func(1, ); // expected-error {{expected expression}}
+}
+}
More information about the cfe-commits
mailing list