Skip to content

Commit

Permalink
Issue 16747 - Cannot have stack allocated classes in @safe code
Browse files Browse the repository at this point in the history
  • Loading branch information
ibuclaw committed Jul 23, 2017
1 parent 9232e99 commit a96b39b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/declaration.c
Original file line number Diff line number Diff line change
Expand Up @@ -2131,7 +2131,7 @@ Expression *VarDeclaration::callScopeDtor(Scope *sc)
Expression *ec;

ec = new VarExp(loc, this);
e = new DeleteExp(loc, ec);
e = new DeleteExp(loc, ec, true);
e->type = Type::tvoid;
break;
}
Expand Down
11 changes: 10 additions & 1 deletion src/expression.c
Original file line number Diff line number Diff line change
Expand Up @@ -9681,9 +9681,10 @@ Expression *NotExp::semantic(Scope *sc)

/************************************************************/

DeleteExp::DeleteExp(Loc loc, Expression *e)
DeleteExp::DeleteExp(Loc loc, Expression *e, bool isRAII)
: UnaExp(loc, TOKdelete, sizeof(DeleteExp), e)
{
this->isRAII = isRAII;
}

Expression *DeleteExp::semantic(Scope *sc)
Expand Down Expand Up @@ -9783,6 +9784,14 @@ Expression *DeleteExp::semantic(Scope *sc)
goto Lerr;
}

if (!sc->intypeof && sc->func &&
!isRAII &&
sc->func->setUnsafe())
{
error("%s is not @safe but is used in @safe function %s", toChars(), sc->func->toChars());
goto Lerr;
}

return this;

Lerr:
Expand Down
3 changes: 2 additions & 1 deletion src/expression.h
Original file line number Diff line number Diff line change
Expand Up @@ -979,8 +979,9 @@ class NotExp : public UnaExp

class DeleteExp : public UnaExp
{
bool isRAII;
public:
DeleteExp(Loc loc, Expression *e);
DeleteExp(Loc loc, Expression *e, bool isRAII);
Expression *semantic(Scope *sc);
Expression *toBoolean(Scope *sc);
void accept(Visitor *v) { v->visit(this); }
Expand Down
2 changes: 1 addition & 1 deletion src/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -7200,7 +7200,7 @@ Expression *Parser::parseUnaryExp()
case TOKdelete:
nextToken();
e = parseUnaryExp();
e = new DeleteExp(loc, e);
e = new DeleteExp(loc, e, false);
break;

case TOKcast: // cast(type) expression
Expand Down

0 comments on commit a96b39b

Please sign in to comment.