[llvm-branch-commits] [clang] 37f7f15 - Diagnose the code with trailing comma in the function call. (#125232)

Tom Stellard via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Feb 14 14:16:13 PST 2025


Author: Haojian Wu
Date: 2025-02-14T14:15:23-08:00
New Revision: 37f7f151e586d3e3e5339286aeb4aac6ad7561ea

URL: https://github.com/llvm/llvm-project/commit/37f7f151e586d3e3e5339286aeb4aac6ad7561ea
DIFF: https://github.com/llvm/llvm-project/commit/37f7f151e586d3e3e5339286aeb4aac6ad7561ea.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

(cherry picked from commit 922f339c4ef3631f66dc4b8caa4c356103dbf69d)

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 aa8b3870a188c..0cadede51a9b3 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -2237,6 +2237,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 llvm-branch-commits mailing list