From 79fe7640d93ec436f1449b97c60ae34e8e409b69 Mon Sep 17 00:00:00 2001 From: Andrew Sukach Date: Sat, 8 Jun 2024 21:45:42 -0400 Subject: [PATCH 1/2] prohibit semicolons in parameter list --- source/parse.h | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/source/parse.h b/source/parse.h index b8d404625b..9651d1cc99 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 { @@ -8506,7 +8507,10 @@ class parser // Then there may be a semicolon // If there is a semicolon, eat it if (!done() && curr().type() == lexeme::Semicolon) { - next(); + if (semicolon_allowed) + next(); + else + error("unexpected semicolon after declaration", {}, {}, {}); } // But if there isn't one and it was required, diagnose an error else if (semicolon_required) { @@ -8932,7 +8936,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 +9094,8 @@ class parser std::move(id), access, is_variadic, - my_stmt + my_stmt, + semicolon_allowed ); if (!n) { pos = start_pos; // backtrack From 0e1adcd9d9de44ddb6d3ebacb7f586b00b6bc991 Mon Sep 17 00:00:00 2001 From: Herb Sutter Date: Sat, 15 Jun 2024 15:19:02 -0700 Subject: [PATCH 2/2] Formatting tweak: `{}` around branch bodies, 4-space indent --- source/parse.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/source/parse.h b/source/parse.h index 9651d1cc99..a541e01f72 100644 --- a/source/parse.h +++ b/source/parse.h @@ -8505,14 +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) { - if (semicolon_allowed) - next(); - else - error("unexpected semicolon after declaration", {}, {}, {}); + // 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);