diff --git a/compiler/src/dmd/cparse.d b/compiler/src/dmd/cparse.d index 33669e38c414..ae17b1c37571 100644 --- a/compiler/src/dmd/cparse.d +++ b/compiler/src/dmd/cparse.d @@ -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; } @@ -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; @@ -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 @@ -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) @@ -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; diff --git a/compiler/src/dmd/parse.d b/compiler/src/dmd/parse.d index 8c0a1b13c999..11d405725693 100644 --- a/compiler/src/dmd/parse.d +++ b/compiler/src/dmd/parse.d @@ -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; @@ -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; @@ -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); @@ -6274,7 +6277,7 @@ LagainStc: _body = null; } else - _body = parseStatement(0); + _body = parseStatement(ParseStatementFlags.semi); s = new AST.PragmaStatement(loc, ident, args, _body); break; } @@ -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 @@ -6342,7 +6345,7 @@ LagainStc: } else { - s = parseStatement(0); + s = parseStatement(ParseStatementFlags.semi); } s = new AST.ScopeStatement(loc, s, token.loc); @@ -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; @@ -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 diff --git a/compiler/src/dmd/statementsem.d b/compiler/src/dmd/statementsem.d index f04541632247..670ab1cab36b 100644 --- a/compiler/src/dmd/statementsem.d +++ b/compiler/src/dmd/statementsem.d @@ -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); diff --git a/compiler/test/fail_compilation/fail4559.d b/compiler/test/fail_compilation/fail4559.d index 657c184d7875..0101ae98bf1a 100644 --- a/compiler/test/fail_compilation/fail4559.d +++ b/compiler/test/fail_compilation/fail4559.d @@ -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 `;` --- */