[llvm-branch-commits] [clang] release/20.x: Diagnose the code with trailing comma in the function call. (#125232) (PR #127215)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Feb 14 07:32:34 PST 2025


https://github.com/llvmbot created https://github.com/llvm/llvm-project/pull/127215

Backport 922f339c4ef3631f66dc4b8caa4c356103dbf69d

Requested by: @hokein

>From b694382296f6ccd756086158528c6114fabeffd2 Mon Sep 17 00:00:00 2001
From: Haojian Wu <hokein.wu at gmail.com>
Date: Fri, 14 Feb 2025 16:21:53 +0100
Subject: [PATCH] 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)
---
 clang/lib/Parse/ParseExpr.cpp  | 2 ++
 clang/test/Parser/recovery.cpp | 7 +++++++
 2 files changed, 9 insertions(+)

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