diff --git a/source/parse.h b/source/parse.h index b8d404625b..a541e01f72 100644 --- a/source/parse.h +++ b/source/parse.h @@ -7731,7 +7731,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 {}; } @@ -8198,7 +8198,8 @@ class parser std::unique_ptr id = {}, accessibility access = {}, bool is_variadic = false, - statement_node* my_stmt = {} + statement_node* my_stmt = {}, + bool semicolon_allowed = true ) -> std::unique_ptr { @@ -8504,11 +8505,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); @@ -8932,7 +8940,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 { @@ -9089,7 +9098,8 @@ class parser std::move(id), access, is_variadic, - my_stmt + my_stmt, + semicolon_allowed ); if (!n) { pos = start_pos; // backtrack