[clang] [Clang] Do not consider a variadic function ellipsis part of a default arg (PR #153496)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 13 14:08:44 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Corentin Jabot (cor3ntin)
<details>
<summary>Changes</summary>
When stashing the tokens of a parameter of a member function, we would munch an ellipsis, as the only considered terminal conditions were `,` and `)`.
Fixes #<!-- -->153445
---
Full diff: https://github.com/llvm/llvm-project/pull/153496.diff
4 Files Affected:
- (modified) clang/docs/ReleaseNotes.rst (+2)
- (modified) clang/lib/Parse/ParseCXXInlineMethods.cpp (+6)
- (modified) clang/test/Parser/cxx-variadic-func.cpp (+12)
- (modified) clang/test/Parser/cxx2c-oxford-variadic-comma.cpp (+1)
``````````diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index d109518bca3f3..be72b040808b3 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -206,6 +206,8 @@ Bug Fixes to C++ Support
casts that are guaranteed to fail (#GH137518).
- Fix bug rejecting partial specialization of variable templates with auto NTTPs (#GH118190).
- Fix a crash when using ``explicit(bool)`` in pre-C++11 language modes. (#GH152729)
+- Fix the parsing of variadic member functions when the ellipis immediately follows a default argument.(#GH153445)
+
Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Parse/ParseCXXInlineMethods.cpp b/clang/lib/Parse/ParseCXXInlineMethods.cpp
index 9a010fb5f3427..74e25002e468b 100644
--- a/clang/lib/Parse/ParseCXXInlineMethods.cpp
+++ b/clang/lib/Parse/ParseCXXInlineMethods.cpp
@@ -1161,6 +1161,12 @@ bool Parser::ConsumeAndStoreInitializer(CachedTokens &Toks,
while (true) {
switch (Tok.getKind()) {
+ case tok::ellipsis:
+ // We found an elipsis at the end of the parameter list;
+ // it is not part of a parameter declaration.
+ if (ParenCount == 1 && NextToken().is(tok::r_paren))
+ return true;
+ goto consume_token;
case tok::comma:
// If we might be in a template, perform a tentative parse to check.
if (!AngleCount)
diff --git a/clang/test/Parser/cxx-variadic-func.cpp b/clang/test/Parser/cxx-variadic-func.cpp
index 98a34d3e1bf67..d1b822e7c3f65 100644
--- a/clang/test/Parser/cxx-variadic-func.cpp
+++ b/clang/test/Parser/cxx-variadic-func.cpp
@@ -6,3 +6,15 @@ void f(...) {
}
void h(int n..., int m); // expected-error {{expected ')'}} expected-note {{to match}}
+
+
+namespace GH153445 {
+void f(int = {}...);
+
+struct S {
+ void f(int = {}...);
+ void g(int...);
+};
+
+void S::g(int = {}...) {}
+}
diff --git a/clang/test/Parser/cxx2c-oxford-variadic-comma.cpp b/clang/test/Parser/cxx2c-oxford-variadic-comma.cpp
index b8015b4815b2e..18ce770851a36 100644
--- a/clang/test/Parser/cxx2c-oxford-variadic-comma.cpp
+++ b/clang/test/Parser/cxx2c-oxford-variadic-comma.cpp
@@ -36,6 +36,7 @@ void o(int x, ...);
struct S {
void p(this S...) {} // expected-warning {{declaration of a variadic function without a comma before '...' is deprecated}}
+ void f(int = {}...); // expected-warning {{declaration of a variadic function without a comma before '...' is deprecated}}
};
template<class ...Ts>
``````````
</details>
https://github.com/llvm/llvm-project/pull/153496
More information about the cfe-commits
mailing list