https://github.com/cor3ntin created https://github.com/llvm/llvm-project/pull/153496
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 >From e7fdb9f9c9d8a58658f89330dea99006b078c2e7 Mon Sep 17 00:00:00 2001 From: Corentin Jabot <corentinja...@gmail.com> Date: Wed, 13 Aug 2025 22:54:07 +0200 Subject: [PATCH] [Clang] Do not consider a variadic function ellipsis part of a default arg 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 --- clang/docs/ReleaseNotes.rst | 2 ++ clang/lib/Parse/ParseCXXInlineMethods.cpp | 6 ++++++ clang/test/Parser/cxx-variadic-func.cpp | 12 ++++++++++++ clang/test/Parser/cxx2c-oxford-variadic-comma.cpp | 1 + 4 files changed, 21 insertions(+) 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> _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits