https://github.com/cor3ntin updated https://github.com/llvm/llvm-project/pull/153496
>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 1/2] [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> >From 0b6e51f454ed69618b3181841d8a3237771c685e Mon Sep 17 00:00:00 2001 From: Corentin Jabot <corentinja...@gmail.com> Date: Thu, 14 Aug 2025 11:12:43 +0200 Subject: [PATCH 2/2] Address feedback --- clang/docs/ReleaseNotes.rst | 1 - clang/test/Parser/cxx-variadic-func.cpp | 9 +++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index be72b040808b3..2892c5132039e 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -208,7 +208,6 @@ Bug Fixes to C++ Support - 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 ^^^^^^^^^^^^^^^^^^^^^^^^^ - Fix incorrect name qualifiers applied to alias CTAD. (#GH136624) diff --git a/clang/test/Parser/cxx-variadic-func.cpp b/clang/test/Parser/cxx-variadic-func.cpp index d1b822e7c3f65..73124b8b1b05b 100644 --- a/clang/test/Parser/cxx-variadic-func.cpp +++ b/clang/test/Parser/cxx-variadic-func.cpp @@ -18,3 +18,12 @@ struct S { void S::g(int = {}...) {} } + + +template <typename ...T> +constexpr int a() {return 1;} + +struct S2 { + template <typename ...Ts> + void f(int = a<Ts...>()...); +}; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits