Skip to content

Commit

Permalink
DIP25: don't forget opAssign
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Jan 26, 2015
1 parent 6e5d1c9 commit 3f2404d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/clone.c
Expand Up @@ -203,7 +203,7 @@ FuncDeclaration *buildOpAssign(StructDeclaration *sd, Scope *sc)
if (!needOpAssign(sd))
return NULL;

//printf("StructDeclaration::buildOpAssign() %s\n", toChars());
//printf("StructDeclaration::buildOpAssign() %s\n", sd->toChars());
StorageClass stc = STCsafe | STCnothrow | STCpure | STCnogc;
Loc declLoc = sd->loc;
Loc loc = Loc(); // internal code should have no loc to prevent coverage
Expand Down Expand Up @@ -238,7 +238,7 @@ FuncDeclaration *buildOpAssign(StructDeclaration *sd, Scope *sc)

Parameters *fparams = new Parameters;
fparams->push(new Parameter(STCnodtor, sd->type, Id::p, NULL));
Type *tf = new TypeFunction(fparams, sd->handleType(), 0, LINKd, stc | STCref);
TypeFunction *tf = new TypeFunction(fparams, sd->handleType(), 0, LINKd, stc | STCref);

FuncDeclaration *fop = new FuncDeclaration(declLoc, Loc(), Id::assign, stc, tf);

Expand Down Expand Up @@ -302,6 +302,7 @@ FuncDeclaration *buildOpAssign(StructDeclaration *sd, Scope *sc)
Statement *s2 = new ReturnStatement(loc, e);

fop->fbody = new CompoundStatement(loc, s1, s2);
tf->isreturn = true;
}

sd->members->push(fop);
Expand Down
3 changes: 3 additions & 0 deletions src/escape.c
Expand Up @@ -291,7 +291,10 @@ bool checkEscapeRef(Scope *sc, Expression *e, bool gag)
}
}
else if (sc->module && sc->module->isRoot())
{
//printf("escaping reference to local ref variable %s\n", v->toChars());
error(loc, "escaping reference to local ref variable %s", v);
}
return;
}

Expand Down
26 changes: 26 additions & 0 deletions test/runnable/testscope2.d
Expand Up @@ -177,6 +177,31 @@ struct S10

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

struct RC
{
this(this) { }
}

struct S11
{
@disable this(this);

void remove()
{
_ptr[0] = _ptr[1];
}

RC* _ptr;
}


void test11()
{
S11 ary;
}

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

void main()
{
test3();
Expand All @@ -185,6 +210,7 @@ void main()
test6();
test7();
test8();
test11();
printf("Success\n");
}

0 comments on commit 3f2404d

Please sign in to comment.