[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
This commit is contained in:
Corentin Jabot 2025-08-14 12:51:58 +02:00 committed by GitHub
parent 8d4f3171fa
commit 186176de45
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 29 additions and 0 deletions

View File

@ -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
^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -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)

View File

@ -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...>()...);
};

View File

@ -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>