Skip to content

Commit 58396fa

Browse files
jobnzhsutter
andauthored
fix: function paramter list can end in comma. Fixes# 613 (#664)
* fix: function paramter list can end in comma. Fixes# 613 * [WIP] add: regression tests * fix: cpp2 does not syntax-check cpp1 * fix: test name such that it fits the naming scheme * Tweak error message wording Signed-off-by: Herb Sutter <herb.sutter@gmail.com> --------- Signed-off-by: Herb Sutter <herb.sutter@gmail.com> Co-authored-by: Herb Sutter <herb.sutter@gmail.com>
1 parent 01962bb commit 58396fa

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
main: (args,) = {}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pure2-bugfix-for-parameter-decl-list.cpp2...
2+
pure2-bugfix-for-parameter-decl-list.cpp2(1,13): error: invalid parameter list: expected expr (at ')')
3+

source/parse.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6182,8 +6182,11 @@ class parser
61826182
auto param = std::make_unique<parameter_declaration_node>();
61836183

61846184
auto count = 1;
6185+
auto expect_another_param_decl = false;
6186+
61856187
while ((param = parameter_declaration(is_returns, is_named, is_template, is_statement)) != nullptr)
61866188
{
6189+
expect_another_param_decl = false;
61876190
param->ordinal = count;
61886191
++count;
61896192

@@ -6209,9 +6212,15 @@ class parser
62096212
}
62106213
return {};
62116214
}
6215+
6216+
expect_another_param_decl = true;
62126217
next();
62136218
}
62146219

6220+
if (expect_another_param_decl) {
6221+
error("invalid parameter list: a comma must be followed by another parameter", true, {}, true);
6222+
}
6223+
62156224
if (curr().type() != closer) {
62166225
if (is_statement) {
62176226
pos = start_pos; // backtrack

0 commit comments

Comments
 (0)