Skip to content

Commit 186176d

Browse files
authored
[Clang] Do not consider a variadic function ellipsis part of a default arg (llvm#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 llvm#153445
1 parent 8d4f317 commit 186176d

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ Bug Fixes to C++ Support
209209
casts that are guaranteed to fail (#GH137518).
210210
- Fix bug rejecting partial specialization of variable templates with auto NTTPs (#GH118190).
211211
- Fix a crash when using ``explicit(bool)`` in pre-C++11 language modes. (#GH152729)
212+
- Fix the parsing of variadic member functions when the ellipis immediately follows a default argument.(#GH153445)
212213

213214
Bug Fixes to AST Handling
214215
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Parse/ParseCXXInlineMethods.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,6 +1161,12 @@ bool Parser::ConsumeAndStoreInitializer(CachedTokens &Toks,
11611161

11621162
while (true) {
11631163
switch (Tok.getKind()) {
1164+
case tok::ellipsis:
1165+
// We found an elipsis at the end of the parameter list;
1166+
// it is not part of a parameter declaration.
1167+
if (ParenCount == 1 && NextToken().is(tok::r_paren))
1168+
return true;
1169+
goto consume_token;
11641170
case tok::comma:
11651171
// If we might be in a template, perform a tentative parse to check.
11661172
if (!AngleCount)

clang/test/Parser/cxx-variadic-func.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,24 @@ void f(...) {
66
}
77

88
void h(int n..., int m); // expected-error {{expected ')'}} expected-note {{to match}}
9+
10+
11+
namespace GH153445 {
12+
void f(int = {}...);
13+
14+
struct S {
15+
void f(int = {}...);
16+
void g(int...);
17+
};
18+
19+
void S::g(int = {}...) {}
20+
}
21+
22+
23+
template <typename ...T>
24+
constexpr int a() {return 1;}
25+
26+
struct S2 {
27+
template <typename ...Ts>
28+
void f(int = a<Ts...>()...);
29+
};

clang/test/Parser/cxx2c-oxford-variadic-comma.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ void o(int x, ...);
3636

3737
struct S {
3838
void p(this S...) {} // expected-warning {{declaration of a variadic function without a comma before '...' is deprecated}}
39+
void f(int = {}...); // expected-warning {{declaration of a variadic function without a comma before '...' is deprecated}}
3940
};
4041

4142
template<class ...Ts>

0 commit comments

Comments
 (0)