Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions compiler/src/dmd/cparse.d
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ final class CParser(AST) : Parser!AST
else if (token.value == TOK.leftCurly)
s = cparseStatement(ParseStatementFlags.curly | ParseStatementFlags.scope_);
else
s = cparseStatement(0);
s = cparseStatement(ParseStatementFlags.semiOk);
s = new AST.LabelStatement(loc, ident, s);
break;
}
Expand Down Expand Up @@ -376,7 +376,7 @@ final class CParser(AST) : Parser!AST
auto statements = new AST.Statements();
while (token.value != TOK.rightCurly && token.value != TOK.endOfFile)
{
statements.push(cparseStatement(ParseStatementFlags.curlyScope));
statements.push(cparseStatement(ParseStatementFlags.semi | ParseStatementFlags.curlyScope));
}
if (endPtr)
*endPtr = token.ptr;
Expand Down Expand Up @@ -525,7 +525,7 @@ final class CParser(AST) : Parser!AST
auto statements = new AST.Statements();
while (token.value != TOK.case_ && token.value != TOK.default_ && token.value != TOK.endOfFile && token.value != TOK.rightCurly)
{
auto cur = cparseStatement(ParseStatementFlags.curlyScope);
auto cur = cparseStatement(ParseStatementFlags.semi | ParseStatementFlags.curlyScope);
statements.push(cur);

// https://issues.dlang.org/show_bug.cgi?id=21739
Expand All @@ -540,7 +540,7 @@ final class CParser(AST) : Parser!AST
}
else
{
s = cparseStatement(0);
s = cparseStatement(ParseStatementFlags.semi);
}
s = new AST.ScopeStatement(loc, s, token.loc);
if (expHigh)
Expand All @@ -560,12 +560,12 @@ final class CParser(AST) : Parser!AST
auto statements = new AST.Statements();
while (token.value != TOK.case_ && token.value != TOK.default_ && token.value != TOK.endOfFile && token.value != TOK.rightCurly)
{
statements.push(cparseStatement(ParseStatementFlags.curlyScope));
statements.push(cparseStatement(ParseStatementFlags.semi | ParseStatementFlags.curlyScope));
}
s = new AST.CompoundStatement(loc, statements);
}
else
s = cparseStatement(0);
s = cparseStatement(ParseStatementFlags.semi);
s = new AST.ScopeStatement(loc, s, token.loc);
s = new AST.DefaultStatement(loc, s);
break;
Expand Down
20 changes: 12 additions & 8 deletions compiler/src/dmd/parse.d
Original file line number Diff line number Diff line change
Expand Up @@ -5184,7 +5184,7 @@ class Parser(AST, Lexer = dmd.lexer.Lexer) : Lexer
case TOK.leftCurly:
if (requireDo)
error("missing `do { ... }` after `in` or `out`");
f.fbody = parseStatement(0);
f.fbody = parseStatement(ParseStatementFlags.semi);
f.endloc = endloc;
break;

Expand Down Expand Up @@ -6024,7 +6024,7 @@ LagainStc:
auto statements = new AST.Statements();
while (token.value != TOK.rightCurly && token.value != TOK.endOfFile)
{
statements.push(parseStatement(ParseStatementFlags.curlyScope));
statements.push(parseStatement(ParseStatementFlags.semi | ParseStatementFlags.curlyScope));
}
if (endPtr)
*endPtr = token.ptr;
Expand Down Expand Up @@ -6057,7 +6057,10 @@ LagainStc:
case TOK.semicolon:
if (!(flags & ParseStatementFlags.semiOk))
{
error("use `{ }` for an empty statement, not `;`");
if (flags & ParseStatementFlags.semi)
deprecation("use `{ }` for an empty statement, not `;`");
else
error("use `{ }` for an empty statement, not `;`");
}
nextToken();
s = new AST.ExpStatement(loc, cast(AST.Expression)null);
Expand Down Expand Up @@ -6274,7 +6277,7 @@ LagainStc:
_body = null;
}
else
_body = parseStatement(0);
_body = parseStatement(ParseStatementFlags.semi);
s = new AST.PragmaStatement(loc, ident, args, _body);
break;
}
Expand Down Expand Up @@ -6327,7 +6330,7 @@ LagainStc:
auto statements = new AST.Statements();
while (token.value != TOK.case_ && token.value != TOK.default_ && token.value != TOK.endOfFile && token.value != TOK.rightCurly)
{
auto cur = parseStatement(ParseStatementFlags.curlyScope);
auto cur = parseStatement(ParseStatementFlags.semi | ParseStatementFlags.curlyScope);
statements.push(cur);

// https://issues.dlang.org/show_bug.cgi?id=21739
Expand All @@ -6342,7 +6345,7 @@ LagainStc:
}
else
{
s = parseStatement(0);
s = parseStatement(ParseStatementFlags.semi);
}
s = new AST.ScopeStatement(loc, s, token.loc);

Expand Down Expand Up @@ -6371,12 +6374,12 @@ LagainStc:
auto statements = new AST.Statements();
while (token.value != TOK.case_ && token.value != TOK.default_ && token.value != TOK.endOfFile && token.value != TOK.rightCurly)
{
statements.push(parseStatement(ParseStatementFlags.curlyScope));
statements.push(parseStatement(ParseStatementFlags.semi | ParseStatementFlags.curlyScope));
}
s = new AST.CompoundStatement(loc, statements);
}
else
s = parseStatement(0);
s = parseStatement(ParseStatementFlags.semi);
s = new AST.ScopeStatement(loc, s, token.loc);
s = new AST.DefaultStatement(loc, s);
break;
Expand Down Expand Up @@ -9687,6 +9690,7 @@ immutable PREC[EXP.max + 1] precedence =

enum ParseStatementFlags : int
{
semi = 1, // empty ';' statements are allowed, but deprecated
scope_ = 2, // start a new scope
curly = 4, // { } statement is required
curlyScope = 8, // { } starts a new scope
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dmd/statementsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -4809,7 +4809,7 @@ private Statements* flatten(Statement statement, Scope* sc)
auto a = new Statements();
while (p.token.value != TOK.endOfFile)
{
Statement s = p.parseStatement(ParseStatementFlags.curlyScope);
Statement s = p.parseStatement(ParseStatementFlags.semi | ParseStatementFlags.curlyScope);
if (!s || global.errors != errors)
return errorStatements();
a.push(s);
Expand Down
8 changes: 4 additions & 4 deletions compiler/test/fail_compilation/fail4559.d
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*
REQUIRED_ARGS:
REQUIRED_ARGS: -o- -de
TEST_OUTPUT:
---
fail_compilation/fail4559.d(13): Error: use `{ }` for an empty statement, not `;`
fail_compilation/fail4559.d(19): Error: use `{ }` for an empty statement, not `;`
fail_compilation/fail4559.d(21): Error: use `{ }` for an empty statement, not `;`
fail_compilation/fail4559.d(13): Deprecation: use `{ }` for an empty statement, not `;`
fail_compilation/fail4559.d(19): Deprecation: use `{ }` for an empty statement, not `;`
fail_compilation/fail4559.d(21): Deprecation: use `{ }` for an empty statement, not `;`
---
*/

Expand Down