Skip to content

Commit

Permalink
Allow pointer type-painting for pointers to global variables
Browse files Browse the repository at this point in the history
  • Loading branch information
don-clugston-sociomantic committed Mar 27, 2013
1 parent aa0ec78 commit 5938730
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/interpret.c
Expand Up @@ -4720,17 +4720,21 @@ Expression *CastExp::interpret(InterState *istate, CtfeGoal goal)
return e;
}
}
if (e1->op == TOKvar)
if (e1->op == TOKvar || e1->op == TOKsymoff)
{ // type painting operation
Type *origType = ((VarExp *)e1)->var->type;
Type *origType = (e1->op == TOKvar) ? ((VarExp *)e1)->var->type :
((SymOffExp *)e1)->var->type;
if (castBackFromVoid && !isSafePointerCast(origType, pointee))
{
error("using void* to reinterpret cast from %s* to %s* is not supported in CTFE",
origType->toChars(), pointee->toChars());
return EXP_CANT_INTERPRET;
}
e = new VarExp(loc, ((VarExp *)e1)->var);
e->type = type;
if (e1->op == TOKvar)
e = new VarExp(loc, ((VarExp *)e1)->var);
else
e = new SymOffExp(loc, ((SymOffExp *)e1)->var, 0);
e->type = to;
return e;
}

Expand Down
2 changes: 2 additions & 0 deletions test/compilable/interpret3.d
Expand Up @@ -2379,6 +2379,8 @@ shared (int) * bug9745(int m)
int test9745(int m)
{
bug9745(m);
// type painting
shared int * w = bug9745(0);
return 1;
}

Expand Down

0 comments on commit 5938730

Please sign in to comment.