Skip to content

Commit e016dc1

Browse files
committed
Add diagnostics for semicolon at the end of function
This change introduce diagnostics when there is a semicolon at the end of the function body: ```cpp g: () = {}; ``` Generates: ``` error: a compound function body shall not end with a semicolon (at ';') ``` And ```cpp g: () = 42;; ``` Generates: ``` error: a short function syntax shall end with a single semicolon (at ';') ```
1 parent f83ca9b commit e016dc1

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

source/parse.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5313,6 +5313,21 @@ class parser
53135313
return {};
53145314
}
53155315

5316+
if (
5317+
n->is_function()
5318+
&& n->initializer
5319+
&& !done() && curr().type() == lexeme::Semicolon
5320+
)
5321+
{
5322+
if (n->initializer->is_compound() && n->has_name()) {
5323+
error("a compound function body shall not end with a semicolon");
5324+
return {};
5325+
} else if (n->initializer->is_expression()) {
5326+
error("a short function syntax shall end with a single semicolon");
5327+
return {};
5328+
}
5329+
}
5330+
53165331
// If this is an implicit constructor, it must have two parameters
53175332
if (n->is_constructor())
53185333
{

0 commit comments

Comments
 (0)