Skip to content

Commit

Permalink
prohibit semicolons in parameter list (#1100)
Browse files Browse the repository at this point in the history
* prohibit semicolons in parameter list

* Formatting tweak: `{}` around branch bodies, 4-space indent

---------

Co-authored-by: Herb Sutter <herb.sutter@gmail.com>
  • Loading branch information
sookach and hsutter authored Jun 15, 2024
1 parent 57a29d1 commit 6156b51
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions source/parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -7732,7 +7732,7 @@ class parser

// Now the main declaration
//
if (!(n->declaration = declaration(false, true, is_template))) {
if (!(n->declaration = declaration(false, true, is_template, {}, false))) {
pos = start_pos; // backtrack
return {};
}
Expand Down Expand Up @@ -8199,7 +8199,8 @@ class parser
std::unique_ptr<unqualified_id_node> id = {},
accessibility access = {},
bool is_variadic = false,
statement_node* my_stmt = {}
statement_node* my_stmt = {},
bool semicolon_allowed = true
)
-> std::unique_ptr<declaration_node>
{
Expand Down Expand Up @@ -8505,11 +8506,18 @@ class parser
}

// Then there may be a semicolon
// If there is a semicolon, eat it
// If there is a semicolon...
if (!done() && curr().type() == lexeme::Semicolon) {
next();
// If it's allowed, eat it
if (semicolon_allowed) {
next();
}
// Otherwise, diagnose an error
else {
error("unexpected semicolon after declaration", {}, {}, {});
}
}
// But if there isn't one and it was required, diagnose an error
// Otherwise if there isn't one and it was required, diagnose an error
else if (semicolon_required) {
if (curr().type() == lexeme::LeftBrace) {
error("expected '=' before '{' - did you mean '= {' ?", true, {}, true);
Expand Down Expand Up @@ -8933,7 +8941,8 @@ class parser
bool semicolon_required = true,
bool is_parameter = false,
bool is_template_parameter = false,
statement_node* my_stmt = {}
statement_node* my_stmt = {},
bool semicolon_allowed = true
)
-> std::unique_ptr<declaration_node>
{
Expand Down Expand Up @@ -9090,7 +9099,8 @@ class parser
std::move(id),
access,
is_variadic,
my_stmt
my_stmt,
semicolon_allowed
);
if (!n) {
pos = start_pos; // backtrack
Expand Down

0 comments on commit 6156b51

Please sign in to comment.