diff --git a/dmd/class.c b/dmd/class.c index c0ee4273..b373db2a 100644 --- a/dmd/class.c +++ b/dmd/class.c @@ -563,8 +563,7 @@ void ClassDeclaration::semantic(Scope *sc) isabstract = 1; sc = sc->push(this); - sc->stc &= ~(STCfinal | STCauto | STCscope | STCstatic | - STCabstract | STCdeprecated); + sc->stc &= STCsafe | STCtrusted | STCsystem; sc->parent = this; sc->inunion = 0; diff --git a/dmd/declaration.c b/dmd/declaration.c index ec316ee3..76abbe03 100644 --- a/dmd/declaration.c +++ b/dmd/declaration.c @@ -762,6 +762,10 @@ void VarDeclaration::semantic(Scope *sc) if (storage_class & STCextern && init) error("extern symbols cannot have initializers"); + AggregateDeclaration *ad = isThis(); + if (ad) + storage_class |= ad->storage_class & STC_TYPECTOR; + /* If auto type inference, do the inference */ int inferred = 0; @@ -1324,6 +1328,27 @@ void VarDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) buf->writenl(); } +AggregateDeclaration *VarDeclaration::isThis() +{ + AggregateDeclaration *ad = NULL; + + if (!(storage_class & (STCstatic | STCextern | STCmanifest | STCtemplateparameter | + STCtls | STCgshared | STCctfe))) + { + if ((storage_class & (STCconst | STCimmutable)) && init) + return NULL; + + for (Dsymbol *s = this; s; s = s->parent) + { + ad = s->isMember(); + if (ad) + break; + if (!s->parent || !s->parent->isTemplateMixin()) break; + } + } + return ad; +} + int VarDeclaration::needThis() { //printf("VarDeclaration::needThis(%s, x%x)\n", toChars(), storage_class); diff --git a/dmd/declaration.h b/dmd/declaration.h index d29ea400..bfefaddc 100644 --- a/dmd/declaration.h +++ b/dmd/declaration.h @@ -304,6 +304,7 @@ struct VarDeclaration : Declaration Type *htype; Initializer *hinit; #endif + AggregateDeclaration *isThis(); int needThis(); int isImportedSymbol(); int isDataseg(); diff --git a/dmd/func.c b/dmd/func.c index 6bf8da02..2af14d22 100644 --- a/dmd/func.c +++ b/dmd/func.c @@ -143,6 +143,7 @@ Dsymbol *FuncDeclaration::syntaxCopy(Dsymbol *s) void FuncDeclaration::semantic(Scope *sc) { TypeFunction *f; + AggregateDeclaration *ad; StructDeclaration *sd; ClassDeclaration *cd; InterfaceDeclaration *id; @@ -201,7 +202,11 @@ void FuncDeclaration::semantic(Scope *sc) linkage = sc->linkage; protection = sc->protection; + storage_class |= sc->stc; + ad = isThis(); + if (ad) + storage_class |= ad->storage_class & (STC_TYPECTOR | STCsynchronized); //printf("function storage_class = x%x\n", storage_class); if (ident == Id::ctor && !isCtorDeclaration()) @@ -232,11 +237,11 @@ void FuncDeclaration::semantic(Scope *sc) #endif #ifdef IN_GCC - AggregateDeclaration *ad; - - ad = parent->isAggregateDeclaration(); - if (ad) - ad->methods.push(this); + { + AggregateDeclaration *ad = parent->isAggregateDeclaration(); + if (ad) + ad->methods.push(this); + } #endif sd = parent->isStructDeclaration(); if (sd)