Skip to content

Commit

Permalink
More fix for issue 12152 - Add setScope() call to be able to resolve …
Browse files Browse the repository at this point in the history
…forward references
  • Loading branch information
9rnsr committed Apr 1, 2015
1 parent ec6df46 commit 8efa502
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/class.c
Expand Up @@ -565,13 +565,37 @@ void ClassDeclaration::semantic(Scope *sc)
* before the members semantic analysis of this class, in order to determine
* vtbl in this class. However if a base class refers the member of this class,
* it can be resolved as a normal forward reference.
* Call addMember() to make this class members visible from the base classes.
* Call addMember() and setScope() to make this class members visible from the base classes.
*/
for (size_t i = 0; i < members->dim; i++)
{
Dsymbol *s = (*members)[i];
s->addMember(sc, this, 1);
}

Scope *sc2 = sc->push(this);
sc2->stc &= STCsafe | STCtrusted | STCsystem;
sc2->parent = this;
sc2->inunion = 0;
if (isCOMclass())
{
if (global.params.isWindows)
sc2->linkage = LINKwindows;
else
sc2->linkage = LINKc;
}
sc2->protection = Prot(PROTpublic);
sc2->explicitProtection = 0;
sc2->structalign = STRUCTALIGN_DEFAULT;
sc2->userAttribDecl = NULL;

for (size_t i = 0; i < members->dim; i++)
{
Dsymbol *s = (*members)[i];
s->setScope(sc2);
}

sc2->pop();
}

for (size_t i = 0; i < baseclasses->dim; i++)
Expand Down
21 changes: 21 additions & 0 deletions test/compilable/testfwdref.d
Expand Up @@ -306,6 +306,27 @@ class E12984a(T) : D12984a!int
}
}

static assert("B.instanceSize = ", __traits(classInstanceSize, B12984a) == (void*).sizeof * 2);
static assert("C.instanceSize = ", __traits(classInstanceSize, C12984a) == (void*).sizeof * 2);

// ----

class B12984b { int b; alias MyD = D12984b!int; }
class C12984b : B12984b { int c; }

class D12984b(T) { int d; alias MyE = E12984b!float; }
class E12984b(T) : D12984b!int
{
int e;
void m()
{
auto c = new C12984b();
}
}

static assert("B.instanceSize = ", __traits(classInstanceSize, B12984b) == (void*).sizeof * 2 + (int).sizeof);
static assert("C.instanceSize = ", __traits(classInstanceSize, C12984b) == (void*).sizeof * 2 + (int).sizeof);

/***************************************************/
// 13860

Expand Down

0 comments on commit 8efa502

Please sign in to comment.