@@ -7732,7 +7732,7 @@ class parser
7732
7732
7733
7733
// Now the main declaration
7734
7734
//
7735
- if (!(n->declaration = declaration (false , true , is_template))) {
7735
+ if (!(n->declaration = declaration (false , true , is_template, {}, false ))) {
7736
7736
pos = start_pos; // backtrack
7737
7737
return {};
7738
7738
}
@@ -8199,7 +8199,8 @@ class parser
8199
8199
std::unique_ptr<unqualified_id_node> id = {},
8200
8200
accessibility access = {},
8201
8201
bool is_variadic = false ,
8202
- statement_node* my_stmt = {}
8202
+ statement_node* my_stmt = {},
8203
+ bool semicolon_allowed = true
8203
8204
)
8204
8205
-> std::unique_ptr<declaration_node>
8205
8206
{
@@ -8505,11 +8506,18 @@ class parser
8505
8506
}
8506
8507
8507
8508
// Then there may be a semicolon
8508
- // If there is a semicolon, eat it
8509
+ // If there is a semicolon...
8509
8510
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
+ }
8511
8519
}
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
8513
8521
else if (semicolon_required) {
8514
8522
if (curr ().type () == lexeme::LeftBrace) {
8515
8523
error (" expected '=' before '{' - did you mean '= {' ?" , true , {}, true );
@@ -8933,7 +8941,8 @@ class parser
8933
8941
bool semicolon_required = true ,
8934
8942
bool is_parameter = false ,
8935
8943
bool is_template_parameter = false ,
8936
- statement_node* my_stmt = {}
8944
+ statement_node* my_stmt = {},
8945
+ bool semicolon_allowed = true
8937
8946
)
8938
8947
-> std::unique_ptr<declaration_node>
8939
8948
{
@@ -9090,7 +9099,8 @@ class parser
9090
9099
std::move (id),
9091
9100
access ,
9092
9101
is_variadic,
9093
- my_stmt
9102
+ my_stmt,
9103
+ semicolon_allowed
9094
9104
);
9095
9105
if (!n) {
9096
9106
pos = start_pos; // backtrack
0 commit comments