Skip to content

Commit 6156b51

Browse files
sookachhsutter
andauthored
prohibit semicolons in parameter list (#1100)
* prohibit semicolons in parameter list * Formatting tweak: `{}` around branch bodies, 4-space indent --------- Co-authored-by: Herb Sutter <[email protected]>
1 parent 57a29d1 commit 6156b51

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

source/parse.h

+17-7
Original file line numberDiff line numberDiff line change
@@ -7732,7 +7732,7 @@ class parser
77327732

77337733
// Now the main declaration
77347734
//
7735-
if (!(n->declaration = declaration(false, true, is_template))) {
7735+
if (!(n->declaration = declaration(false, true, is_template, {}, false))) {
77367736
pos = start_pos; // backtrack
77377737
return {};
77387738
}
@@ -8199,7 +8199,8 @@ class parser
81998199
std::unique_ptr<unqualified_id_node> id = {},
82008200
accessibility access = {},
82018201
bool is_variadic = false,
8202-
statement_node* my_stmt = {}
8202+
statement_node* my_stmt = {},
8203+
bool semicolon_allowed = true
82038204
)
82048205
-> std::unique_ptr<declaration_node>
82058206
{
@@ -8505,11 +8506,18 @@ class parser
85058506
}
85068507

85078508
// Then there may be a semicolon
8508-
// If there is a semicolon, eat it
8509+
// If there is a semicolon...
85098510
if (!done() && curr().type() == lexeme::Semicolon) {
8510-
next();
8511+
// If it's allowed, eat it
8512+
if (semicolon_allowed) {
8513+
next();
8514+
}
8515+
// Otherwise, diagnose an error
8516+
else {
8517+
error("unexpected semicolon after declaration", {}, {}, {});
8518+
}
85118519
}
8512-
// But if there isn't one and it was required, diagnose an error
8520+
// Otherwise if there isn't one and it was required, diagnose an error
85138521
else if (semicolon_required) {
85148522
if (curr().type() == lexeme::LeftBrace) {
85158523
error("expected '=' before '{' - did you mean '= {' ?", true, {}, true);
@@ -8933,7 +8941,8 @@ class parser
89338941
bool semicolon_required = true,
89348942
bool is_parameter = false,
89358943
bool is_template_parameter = false,
8936-
statement_node* my_stmt = {}
8944+
statement_node* my_stmt = {},
8945+
bool semicolon_allowed = true
89378946
)
89388947
-> std::unique_ptr<declaration_node>
89398948
{
@@ -9090,7 +9099,8 @@ class parser
90909099
std::move(id),
90919100
access,
90929101
is_variadic,
9093-
my_stmt
9102+
my_stmt,
9103+
semicolon_allowed
90949104
);
90959105
if (!n) {
90969106
pos = start_pos; // backtrack

0 commit comments

Comments
 (0)