Author: Corentin Jabot Date: 2025-08-14T12:51:58+02:00 New Revision: 186176de459bd53e925ddc9c37500885551e1966
URL: https://github.com/llvm/llvm-project/commit/186176de459bd53e925ddc9c37500885551e1966 DIFF: https://github.com/llvm/llvm-project/commit/186176de459bd53e925ddc9c37500885551e1966.diff LOG: [Clang] Do not consider a variadic function ellipsis part of a default arg (#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 Added: Modified: clang/docs/ReleaseNotes.rst clang/lib/Parse/ParseCXXInlineMethods.cpp clang/test/Parser/cxx-variadic-func.cpp clang/test/Parser/cxx2c-oxford-variadic-comma.cpp Removed: ################################################################################ diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 143502237cfda..ee27c3bd3f7b9 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -209,6 +209,7 @@ 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..73124b8b1b05b 100644 --- a/clang/test/Parser/cxx-variadic-func.cpp +++ b/clang/test/Parser/cxx-variadic-func.cpp @@ -6,3 +6,24 @@ 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 = {}...) {} +} + + +template <typename ...T> +constexpr int a() {return 1;} + +struct S2 { + template <typename ...Ts> + void f(int = a<Ts...>()...); +}; 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