[clang] [C23][Parser] Accept single variadic parameter function declarator in type name (PR #145362)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 23 09:53:24 PDT 2025
https://github.com/yronglin created https://github.com/llvm/llvm-project/pull/145362
Fixs: https://github.com/llvm/llvm-project/issues/145250.
>From 967ba04e0a0f11edbaf36ce6edb51f6ab4fcb56b Mon Sep 17 00:00:00 2001
From: yronglin <yronglin777 at gmail.com>
Date: Tue, 24 Jun 2025 00:51:32 +0800
Subject: [PATCH] [C23][Parser] Accept single variadic parameter function
declarator in type name
Signed-off-by: yronglin <yronglin777 at gmail.com>
---
clang/docs/ReleaseNotes.rst | 2 ++
clang/lib/Parse/ParseDecl.cpp | 3 ++-
clang/test/C/C23/n2975.c | 12 ++++++++++++
3 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 96477ef6ddc9a..89d86c3371247 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -295,6 +295,8 @@ C23 Feature Support
type. Fixes #GH140887
- Documented `WG14 N3006 <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3006.htm>`_
which clarified how Clang is handling underspecified object declarations.
+- Clang now accepts single variadic parameter in type-name. It's a part of
+ `WG14 N2975 <https://open-std.org/JTC1/SC22/WG14/www/docs/n2975.pdf>`_
C11 Feature Support
^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 02f33511dbd61..7e739e09b15e8 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -7048,7 +7048,8 @@ void Parser::ParseParenDeclarator(Declarator &D) {
// paren, because we haven't seen the identifier yet.
isGrouping = true;
} else if (Tok.is(tok::r_paren) || // 'int()' is a function.
- (getLangOpts().CPlusPlus && Tok.is(tok::ellipsis) &&
+ ((getLangOpts().CPlusPlus || getLangOpts().C23) &&
+ Tok.is(tok::ellipsis) &&
NextToken().is(tok::r_paren)) || // C++ int(...)
isDeclarationSpecifier(
ImplicitTypenameContext::No) || // 'int(int)' is a function.
diff --git a/clang/test/C/C23/n2975.c b/clang/test/C/C23/n2975.c
index 6e7c936855e51..854afeff7a2b7 100644
--- a/clang/test/C/C23/n2975.c
+++ b/clang/test/C/C23/n2975.c
@@ -51,3 +51,15 @@ void use(void) {
// ...including conversion errors.
fp other_local = diag; // expected-error {{incompatible function pointer types initializing 'fp' (aka 'void (*)(...)') with an expression of type 'void (int, int, ...)'}}
}
+
+// int(...) not parsed as variadic function type.
+// https://github.com/llvm/llvm-project/issues/145250
+int va_fn(...); // expected-warning {{'...' as the only parameter of a function is incompatible with C standards before C23}}
+
+// As typeof() argument
+typeof(int(...))*fn_ptr = &va_fn; // expected-warning {{'...' as the only parameter of a function is incompatible with C standards before C23}} \
+ // expected-warning {{'typeof' is incompatible with C standards before C23}}
+
+// As _Generic association type
+int i = _Generic(typeof(va_fn), int(...):1); // expected-warning {{'...' as the only parameter of a function is incompatible with C standards before C23}} \
+ // expected-warning {{'typeof' is incompatible with C standards before C23}}
More information about the cfe-commits
mailing list