Skip to content

Commit

Permalink
rewrite of pull 66
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Jun 5, 2011
1 parent b9e5a15 commit 1d865ec
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 16 deletions.
45 changes: 30 additions & 15 deletions src/clone.c
Expand Up @@ -338,21 +338,26 @@ FuncDeclaration *StructDeclaration::buildCpCtor(Scope *sc)
fcp = new FuncDeclaration(loc, 0, Id::cpctor, STCundefined, ftype);
fcp->storage_class |= postblit->storage_class & STCdisable;

// Build *this = p;
Expression *e = new ThisExp(0);
if (!(fcp->storage_class & STCdisable))
{
// Build *this = p;
Expression *e = new ThisExp(0);
#if !STRUCTTHISREF
e = new PtrExp(0, e);
e = new PtrExp(0, e);
#endif
AssignExp *ea = new AssignExp(0, e, new IdentifierExp(0, Id::p));
ea->op = TOKblit;
Statement *s = new ExpStatement(0, ea);
AssignExp *ea = new AssignExp(0, e, new IdentifierExp(0, Id::p));
ea->op = TOKblit;
Statement *s = new ExpStatement(0, ea);

// Build postBlit();
e = new VarExp(0, postblit, 0);
e = new CallExp(0, e);
// Build postBlit();
e = new VarExp(0, postblit, 0);
e = new CallExp(0, e);

s = new CompoundStatement(0, s, new ExpStatement(0, e));
fcp->fbody = s;
s = new CompoundStatement(0, s, new ExpStatement(0, e));
fcp->fbody = s;
}
else
fcp->fbody = new ExpStatement(0, (Expression *)NULL);

members->push(fcp);

Expand Down Expand Up @@ -401,12 +406,17 @@ FuncDeclaration *StructDeclaration::buildPostBlit(Scope *sc)
{ TypeStruct *ts = (TypeStruct *)tv;
StructDeclaration *sd = ts->sym;
if (sd->postblit)
{ Expression *ex;

{
stc |= sd->postblit->storage_class & STCdisable;

if (stc & STCdisable)
{
e = NULL;
break;
}

// this.v
ex = new ThisExp(0);
Expression *ex = new ThisExp(0);
ex = new DotVarExp(0, ex, v, 0);

if (dim == 1)
Expand All @@ -432,7 +442,7 @@ FuncDeclaration *StructDeclaration::buildPostBlit(Scope *sc)

/* Build our own "postblit" which executes e
*/
if (e)
if (e || (stc & STCdisable))
{ //printf("Building __fieldPostBlit()\n");
PostBlitDeclaration *dd = new PostBlitDeclaration(loc, 0, Lexer::idPool("__fieldPostBlit"));
dd->storage_class |= stc;
Expand All @@ -455,6 +465,11 @@ FuncDeclaration *StructDeclaration::buildPostBlit(Scope *sc)
for (size_t i = 0; i < postblits.dim; i++)
{ FuncDeclaration *fd = (FuncDeclaration *)postblits.data[i];
stc |= fd->storage_class & STCdisable;
if (stc & STCdisable)
{
e = NULL;
break;
}
Expression *ex = new ThisExp(0);
ex = new DotVarExp(0, ex, fd, 0);
ex = new CallExp(0, ex);
Expand Down
2 changes: 1 addition & 1 deletion src/typinf.c
Expand Up @@ -624,7 +624,7 @@ void TypeInfoStructDeclaration::toDt(dt_t **pdt)

// xpostblit
FuncDeclaration *spostblit = sd->postblit;
if (spostblit)
if (spostblit && !(spostblit->storage_class & STCdisable))
dtxoff(pdt, spostblit->toSymbol(), 0, TYnptr);
else
dtsize_t(pdt, 0); // xpostblit
Expand Down
17 changes: 17 additions & 0 deletions test/runnable/xtest46.d
Expand Up @@ -1773,12 +1773,29 @@ struct S95

@disable void foo95() { }

struct T95A
{
@disable this(this);
}

struct S95A
{
T95A t;
}

@disable void foo95A() { }

void test95()
{
S95 s;
S95 t;
static assert(!__traits(compiles, t = s));
static assert(!__traits(compiles, foo95()));

S95A u;
S95A v;
static assert(!__traits(compiles, v = u));
static assert(!__traits(compiles, foo95A()));
}

/***************************************************/
Expand Down

0 comments on commit 1d865ec

Please sign in to comment.