Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

Changeset 781

Show
Ignore:
Timestamp:
12/05/10 20:54:55 (14 years ago)
Author:
walter
Message:

bugzilla 5110 Excess attribute propagation of structs and classes

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/dmd-1.x/src/class.c

    r650 r781  
    544544                        } 
    545545                    } 
    546546                    else 
    547547                        assert(0); 
    548548                    assert(!vthis); 
    549549                    vthis = new ThisDeclaration(loc, t); 
    550550                    members->push(vthis); 
    551551                } 
    552552            } 
    553553        } 
    554554    } 
    555555 
    556556    if (storage_class & STCauto) 
    557557        error("storage class 'auto' is invalid when declaring a class, did you mean to use 'scope'?"); 
    558558    if (storage_class & STCscope) 
    559559        isscope = 1; 
    560560    if (storage_class & STCabstract) 
    561561        isabstract = 1; 
    562562 
    563563    sc = sc->push(this); 
    564     sc->stc &= ~(STCfinal | STCauto | STCscope | STCstatic | 
    565                  STCabstract | STCdeprecated); 
     564    sc->stc &= STCsafe | STCtrusted | STCsystem; 
    566565    sc->parent = this; 
    567566    sc->inunion = 0; 
    568567 
    569568    if (isCOMclass()) 
    570569    { 
    571570#if _WIN32 
    572571        sc->linkage = LINKwindows; 
    573572#else 
    574573        /* This enables us to use COM objects under Linux and 
    575574         * work with things like XPCOM 
    576575         */ 
    577576        sc->linkage = LINKc; 
    578577#endif 
    579578    } 
    580579    sc->protection = PROTpublic; 
    581580    sc->explicitProtection = 0; 
    582581    sc->structalign = 8; 
    583582    structalign = sc->structalign; 
    584583    if (baseClass) 
    585584    {   sc->offset = baseClass->structsize; 
  • branches/dmd-1.x/src/declaration.c

    r754 r781  
    728728    else 
    729729        sv->hinit = hinit->syntaxCopy(); 
    730730#endif 
    731731    return sv; 
    732732} 
    733733 
    734734void VarDeclaration::semantic(Scope *sc) 
    735735{ 
    736736#if 0 
    737737    printf("VarDeclaration::semantic('%s', parent = '%s')\n", toChars(), sc->parent->toChars()); 
    738738    printf(" type = %s\n", type ? type->toChars() : "null"); 
    739739    printf(" stc = x%x\n", sc->stc); 
    740740    printf(" storage_class = x%x\n", storage_class); 
    741741    printf("linkage = %d\n", sc->linkage); 
    742742    //if (strcmp(toChars(), "mul") == 0) halt(); 
    743743#endif 
    744744 
    745745    storage_class |= sc->stc; 
    746746    if (storage_class & STCextern && init) 
    747747        error("extern symbols cannot have initializers"); 
     748 
     749    AggregateDeclaration *ad = isThis(); 
     750    if (ad) 
     751        storage_class |= ad->storage_class & STC_TYPECTOR; 
    748752 
    749753    /* If auto type inference, do the inference 
    750754     */ 
    751755    int inferred = 0; 
    752756    if (!type) 
    753757    {   inuse++; 
    754758        type = init->inferType(sc); 
    755759        inuse--; 
    756760        inferred = 1; 
    757761 
    758762        /* This is a kludge to support the existing syntax for RAII 
    759763         * declarations. 
    760764         */ 
    761765        storage_class &= ~STCauto; 
    762766        originalType = type; 
    763767    } 
    764768    else 
    765769    {   if (!originalType) 
    766770            originalType = type; 
    767771        type = type->semantic(loc, sc); 
     
    12771281     * too. 
    12781282     */ 
    12791283    if (type) 
    12801284        type->toCBuffer(buf, ident, hgs); 
    12811285    else 
    12821286        buf->writestring(ident->toChars()); 
    12831287    if (init) 
    12841288    {   buf->writestring(" = "); 
    12851289#if DMDV2 
    12861290        ExpInitializer *ie = init->isExpInitializer(); 
    12871291        if (ie && (ie->exp->op == TOKconstruct || ie->exp->op == TOKblit)) 
    12881292            ((AssignExp *)ie->exp)->e2->toCBuffer(buf, hgs); 
    12891293        else 
    12901294#endif 
    12911295            init->toCBuffer(buf, hgs); 
    12921296    } 
    12931297    buf->writeByte(';'); 
    12941298    buf->writenl(); 
    12951299} 
    12961300 
     1301AggregateDeclaration *VarDeclaration::isThis() 
     1302{ 
     1303    AggregateDeclaration *ad = NULL; 
     1304 
     1305    if (!(storage_class & (STCstatic | STCextern | STCmanifest | STCtemplateparameter | 
     1306                           STCtls | STCgshared | STCctfe))) 
     1307    { 
     1308        if ((storage_class & (STCconst | STCimmutable)) && init) 
     1309            return NULL; 
     1310 
     1311        for (Dsymbol *s = this; s; s = s->parent) 
     1312        { 
     1313            ad = s->isMember(); 
     1314            if (ad) 
     1315                break; 
     1316            if (!s->parent || !s->parent->isTemplateMixin()) break; 
     1317        } 
     1318    } 
     1319    return ad; 
     1320} 
     1321 
    12971322int VarDeclaration::needThis() 
    12981323{ 
    12991324    //printf("VarDeclaration::needThis(%s, x%x)\n", toChars(), storage_class); 
    13001325    return storage_class & STCfield; 
    13011326} 
    13021327 
    13031328int VarDeclaration::isImportedSymbol() 
    13041329{ 
    13051330    if (protection == PROTexport && !init && (isStatic() || isConst() || parent->isModule())) 
    13061331        return TRUE; 
    13071332    return FALSE; 
    13081333} 
    13091334 
    13101335void VarDeclaration::checkCtorConstInit() 
    13111336{ 
    13121337    if (ctorinit == 0 && isCtorinit() && !(storage_class & STCfield)) 
    13131338        error("missing initializer in static constructor for const variable"); 
    13141339} 
    13151340 
    13161341/************************************ 
  • branches/dmd-1.x/src/declaration.h

    r719 r781  
    258258    int canassign;              // it can be assigned to 
    259259    Dsymbol *aliassym;          // if redone as alias to another symbol 
    260260    Expression *value;          // when interpreting, this is the value 
    261261                                // (NULL if value not determinable) 
    262262#if DMDV2 
    263263    VarDeclaration *rundtor;    // if !NULL, rundtor is tested at runtime to see 
    264264                                // if the destructor should be run. Used to prevent 
    265265                                // dtor calls on postblitted vars 
    266266#endif 
    267267 
    268268    VarDeclaration(Loc loc, Type *t, Identifier *id, Initializer *init); 
    269269    Dsymbol *syntaxCopy(Dsymbol *); 
    270270    void semantic(Scope *sc); 
    271271    void semantic2(Scope *sc); 
    272272    const char *kind(); 
    273273    void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 
    274274#ifdef _DH 
    275275    Type *htype; 
    276276    Initializer *hinit; 
    277277#endif 
     278    AggregateDeclaration *isThis(); 
    278279    int needThis(); 
    279280    int isImportedSymbol(); 
    280281    int isDataseg(); 
    281282    int isThreadlocal(); 
    282283    int isCTFE(); 
    283284    int hasPointers(); 
    284285#if DMDV2 
    285286    int canTakeAddressOf(); 
    286287    int needsAutoDtor(); 
    287288#endif 
    288289    Expression *callScopeDtor(Scope *sc); 
    289290    ExpInitializer *getExpInitializer(); 
    290291    Expression *getConstInitializer(); 
    291292    void checkCtorConstInit(); 
    292293    void checkNestedReference(Scope *sc, Loc loc); 
    293294    Dsymbol *toAlias(); 
    294295 
    295296    Symbol *toSymbol(); 
    296297    void toObjFile(int multiobj);                       // compile to .obj file 
    297298    int cvMember(unsigned char *p); 
  • branches/dmd-1.x/src/func.c

    r738 r781  
    9292    FuncDeclaration *f; 
    9393 
    9494    //printf("FuncDeclaration::syntaxCopy('%s')\n", toChars()); 
    9595    if (s) 
    9696        f = (FuncDeclaration *)s; 
    9797    else 
    9898        f = new FuncDeclaration(loc, endloc, ident, storage_class, type->syntaxCopy()); 
    9999    f->outId = outId; 
    100100    f->frequire = frequire ? frequire->syntaxCopy() : NULL; 
    101101    f->fensure  = fensure  ? fensure->syntaxCopy()  : NULL; 
    102102    f->fbody    = fbody    ? fbody->syntaxCopy()    : NULL; 
    103103    assert(!fthrows); // deprecated 
    104104    return f; 
    105105} 
    106106 
    107107 
    108108// Do the semantic analysis on the external interface to the function. 
    109109 
    110110void FuncDeclaration::semantic(Scope *sc) 
    111111{   TypeFunction *f; 
     112    AggregateDeclaration *ad; 
    112113    StructDeclaration *sd; 
    113114    ClassDeclaration *cd; 
    114115    InterfaceDeclaration *id; 
    115116    Dsymbol *pd; 
    116117 
    117118#if 0 
    118119    printf("FuncDeclaration::semantic(sc = %p, this = %p, '%s', linkage = %d)\n", sc, this, toPrettyChars(), sc->linkage); 
    119120    if (isFuncLiteralDeclaration()) 
    120121        printf("\tFuncLiteralDeclaration()\n"); 
    121122    printf("sc->parent = %s, parent = %s\n", sc->parent->toChars(), parent ? parent->toChars() : ""); 
    122123    printf("type: %p, %s\n", type, type->toChars()); 
    123124#endif 
    124125 
    125126    if (semanticRun != PASSinit && isFuncLiteralDeclaration()) 
    126127    { 
    127128        /* Member functions that have return types that are 
    128129         * forward references can have semantic() run more than 
    129130         * once on them. 
    130131         * See test\interface2.d, test20 
    131132         */ 
     
    151153    foverrides.setDim(0);       // reset in case semantic() is being retried for this function 
    152154 
    153155    if (!originalType) 
    154156        originalType = type; 
    155157    if (!type->deco) 
    156158    { 
    157159        type = type->semantic(loc, sc); 
    158160    } 
    159161    //type->print(); 
    160162    if (type->ty != Tfunction) 
    161163    { 
    162164        error("%s must be a function", toChars()); 
    163165        return; 
    164166    } 
    165167    f = (TypeFunction *)(type); 
    166168    size_t nparams = Parameter::dim(f->parameters); 
    167169 
    168170    linkage = sc->linkage; 
    169171    protection = sc->protection; 
    170172    storage_class |= sc->stc; 
     173    ad = isThis(); 
     174    if (ad) 
     175        storage_class |= ad->storage_class & (STC_TYPECTOR | STCsynchronized); 
    171176    //printf("function storage_class = x%x\n", storage_class); 
    172177 
    173178    if (ident == Id::ctor && !isCtorDeclaration()) 
    174179        error("_ctor is reserved for constructors"); 
    175180 
    176181    if (isConst() || isAuto() || isScope()) 
    177182        error("functions cannot be const or auto"); 
    178183 
    179184    if (isAbstract() && !isVirtual()) 
    180185        error("non-virtual functions cannot be abstract"); 
    181186 
    182187    if (isAbstract() && isFinal()) 
    183188        error("cannot be both final and abstract"); 
    184189#if 0 
    185190    if (isAbstract() && fbody) 
    186191        error("abstract functions cannot have bodies"); 
    187192#endif 
    188193 
    189194#if 0 
    190195    if (isStaticConstructor() || isStaticDestructor()) 
    191196    { 
    192197        if (!isStatic() || type->nextOf()->ty != Tvoid) 
    193198            error("static constructors / destructors must be static void"); 
    194199        if (f->arguments && f->arguments->dim) 
    195200            error("static constructors / destructors must have empty parameter list"); 
    196201        // BUG: check for invalid storage classes 
    197202    } 
    198203#endif 
    199204 
    200205#ifdef IN_GCC 
    201     AggregateDeclaration *ad; 
    202  
    203     ad = parent->isAggregateDeclaration(); 
    204     if (ad) 
    205         ad->methods.push(this); 
     206    { 
     207        AggregateDeclaration *ad = parent->isAggregateDeclaration(); 
     208        if (ad) 
     209            ad->methods.push(this); 
     210    } 
    206211#endif 
    207212    sd = parent->isStructDeclaration(); 
    208213    if (sd) 
    209214    { 
    210215        // Verify no constructors, destructors, etc. 
    211216        if (isCtorDeclaration() || 
    212217            isDtorDeclaration() 
    213218            //|| isInvariantDeclaration() 
    214219            //|| isUnitTestDeclaration() 
    215220           ) 
    216221        { 
    217222            error("special member functions not allowed for %ss", sd->kind()); 
    218223        } 
    219224 
    220225#if 0 
    221226        if (!sd->inv) 
    222227            sd->inv = isInvariantDeclaration(); 
    223228 
    224229        if (!sd->aggNew) 
    225230            sd->aggNew = isNewDeclaration(); 
  • trunk/src/class.c

    r776 r781  
    561561                } 
    562562            } 
    563563        } 
    564564    } 
    565565 
    566566    if (storage_class & STCauto) 
    567567        error("storage class 'auto' is invalid when declaring a class, did you mean to use 'scope'?"); 
    568568    if (storage_class & STCscope) 
    569569        isscope = 1; 
    570570    if (storage_class & STCabstract) 
    571571        isabstract = 1; 
    572572 
    573573    if (storage_class & STCimmutable) 
    574574        type = type->addMod(MODimmutable); 
    575575    if (storage_class & STCconst) 
    576576        type = type->addMod(MODconst); 
    577577    if (storage_class & STCshared) 
    578578        type = type->addMod(MODshared); 
    579579 
    580580    sc = sc->push(this); 
    581     sc->stc &= ~(STCfinal | STCauto | STCscope | STCstatic | 
    582                  STCabstract | STCdeprecated | STC_TYPECTOR | STCtls | STCgshared)
    583     sc->stc |= storage_class & STC_TYPECTOR
     581    //sc->stc &= ~(STCfinal | STCauto | STCscope | STCstatic | STCabstract | STCdeprecated | STC_TYPECTOR | STCtls | STCgshared); 
     582    //sc->stc |= storage_class & STC_TYPECTOR
     583    sc->stc &= STCsafe | STCtrusted | STCsystem
    584584    sc->parent = this; 
    585585    sc->inunion = 0; 
    586586 
    587587    if (isCOMclass()) 
    588588    { 
    589589#if _WIN32 
    590590        sc->linkage = LINKwindows; 
    591591#else 
    592592        /* This enables us to use COM objects under Linux and 
    593593         * work with things like XPCOM 
    594594         */ 
    595595        sc->linkage = LINKc; 
    596596#endif 
    597597    } 
    598598    sc->protection = PROTpublic; 
    599599    sc->explicitProtection = 0; 
    600600    sc->structalign = 8; 
    601601    structalign = sc->structalign; 
    602602    if (baseClass) 
    603603    {   sc->offset = baseClass->structsize; 
  • trunk/src/declaration.c

    r780 r781  
    718718    printf(" stc = x%x\n", sc->stc); 
    719719    printf(" storage_class = x%x\n", storage_class); 
    720720    printf("linkage = %d\n", sc->linkage); 
    721721    //if (strcmp(toChars(), "mul") == 0) halt(); 
    722722#endif 
    723723 
    724724//    if (sem > SemanticStart) 
    725725//      return; 
    726726//    sem = SemanticIn; 
    727727 
    728728    if (scope) 
    729729    {   sc = scope; 
    730730        scope = NULL; 
    731731    } 
    732732 
    733733    /* Pick up storage classes from context, but skip synchronized 
    734734     */ 
    735735    storage_class |= (sc->stc & ~STCsynchronized); 
    736736    if (storage_class & STCextern && init) 
    737737        error("extern symbols cannot have initializers"); 
     738 
     739    AggregateDeclaration *ad = isThis(); 
     740    if (ad) 
     741        storage_class |= ad->storage_class & STC_TYPECTOR; 
    738742 
    739743    /* If auto type inference, do the inference 
    740744     */ 
    741745    int inferred = 0; 
    742746    if (!type) 
    743747    {   inuse++; 
    744748 
    745749        ArrayInitializer *ai = init->isArrayInitializer(); 
    746750        if (ai) 
    747751        {   Expression *e; 
    748752            if (ai->isAssociativeArray()) 
    749753                e = ai->toAssocArrayLiteral(); 
    750754            else 
    751755                e = init->toExpression(); 
    752756            if (!e) 
    753757            { 
    754758                error("cannot infer type from initializer"); 
    755759                e = new ErrorExp(); 
    756760            } 
    757761            init = new ExpInitializer(e->loc, e); 
     
    13781382     * too. 
    13791383     */ 
    13801384    if (type) 
    13811385        type->toCBuffer(buf, ident, hgs); 
    13821386    else 
    13831387        buf->writestring(ident->toChars()); 
    13841388    if (init) 
    13851389    {   buf->writestring(" = "); 
    13861390#if DMDV2 
    13871391        ExpInitializer *ie = init->isExpInitializer(); 
    13881392        if (ie && (ie->exp->op == TOKconstruct || ie->exp->op == TOKblit)) 
    13891393            ((AssignExp *)ie->exp)->e2->toCBuffer(buf, hgs); 
    13901394        else 
    13911395#endif 
    13921396            init->toCBuffer(buf, hgs); 
    13931397    } 
    13941398    buf->writeByte(';'); 
    13951399    buf->writenl(); 
    13961400} 
    13971401 
     1402AggregateDeclaration *VarDeclaration::isThis() 
     1403{ 
     1404    AggregateDeclaration *ad = NULL; 
     1405 
     1406    if (!(storage_class & (STCstatic | STCextern | STCmanifest | STCtemplateparameter | 
     1407                           STCtls | STCgshared | STCctfe))) 
     1408    { 
     1409        if ((storage_class & (STCconst | STCimmutable | STCwild)) && init) 
     1410            return NULL; 
     1411 
     1412        for (Dsymbol *s = this; s; s = s->parent) 
     1413        { 
     1414            ad = s->isMember(); 
     1415            if (ad) 
     1416                break; 
     1417            if (!s->parent || !s->parent->isTemplateMixin()) break; 
     1418        } 
     1419    } 
     1420    return ad; 
     1421} 
     1422 
    13981423int VarDeclaration::needThis() 
    13991424{ 
    14001425    //printf("VarDeclaration::needThis(%s, x%x)\n", toChars(), storage_class); 
    14011426    return storage_class & STCfield; 
    14021427} 
    14031428 
    14041429int VarDeclaration::isImportedSymbol() 
    14051430{ 
    14061431    if (protection == PROTexport && !init && 
    14071432        (storage_class & STCstatic || parent->isModule())) 
    14081433        return TRUE; 
    14091434    return FALSE; 
    14101435} 
    14111436 
    14121437void VarDeclaration::checkCtorConstInit() 
    14131438{ 
    14141439#if 0 /* doesn't work if more than one static ctor */ 
    14151440    if (ctorinit == 0 && isCtorinit() && !(storage_class & STCfield)) 
    14161441        error("missing initializer in static constructor for const variable"); 
    14171442#endif 
  • trunk/src/declaration.h

    r756 r781  
    253253    int canassign;              // it can be assigned to 
    254254    Dsymbol *aliassym;          // if redone as alias to another symbol 
    255255    Expression *value;          // when interpreting, this is the value 
    256256                                // (NULL if value not determinable) 
    257257#if DMDV2 
    258258    VarDeclaration *rundtor;    // if !NULL, rundtor is tested at runtime to see 
    259259                                // if the destructor should be run. Used to prevent 
    260260                                // dtor calls on postblitted vars 
    261261#endif 
    262262 
    263263    VarDeclaration(Loc loc, Type *t, Identifier *id, Initializer *init); 
    264264    Dsymbol *syntaxCopy(Dsymbol *); 
    265265    void semantic(Scope *sc); 
    266266    void semantic2(Scope *sc); 
    267267    const char *kind(); 
    268268    void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 
    269269#ifdef _DH 
    270270    Type *htype; 
    271271    Initializer *hinit; 
    272272#endif 
     273    AggregateDeclaration *isThis(); 
    273274    int needThis(); 
    274275    int isImportedSymbol(); 
    275276    int isDataseg(); 
    276277    int isThreadlocal(); 
    277278    int isCTFE(); 
    278279    int hasPointers(); 
    279280#if DMDV2 
    280281    int canTakeAddressOf(); 
    281282    int needsAutoDtor(); 
    282283#endif 
    283284    Expression *callScopeDtor(Scope *sc); 
    284285    ExpInitializer *getExpInitializer(); 
    285286    Expression *getConstInitializer(); 
    286287    void checkCtorConstInit(); 
    287288    void checkNestedReference(Scope *sc, Loc loc); 
    288289    Dsymbol *toAlias(); 
    289290 
    290291    Symbol *toSymbol(); 
    291292    void toObjFile(int multiobj);                       // compile to .obj file 
    292293    int cvMember(unsigned char *p); 
  • trunk/src/func.c

    r756 r781  
    9292    FuncDeclaration *f; 
    9393 
    9494    //printf("FuncDeclaration::syntaxCopy('%s')\n", toChars()); 
    9595    if (s) 
    9696        f = (FuncDeclaration *)s; 
    9797    else 
    9898        f = new FuncDeclaration(loc, endloc, ident, storage_class, type->syntaxCopy()); 
    9999    f->outId = outId; 
    100100    f->frequire = frequire ? frequire->syntaxCopy() : NULL; 
    101101    f->fensure  = fensure  ? fensure->syntaxCopy()  : NULL; 
    102102    f->fbody    = fbody    ? fbody->syntaxCopy()    : NULL; 
    103103    assert(!fthrows); // deprecated 
    104104    return f; 
    105105} 
    106106 
    107107 
    108108// Do the semantic analysis on the external interface to the function. 
    109109 
    110110void FuncDeclaration::semantic(Scope *sc) 
    111111{   TypeFunction *f; 
     112    AggregateDeclaration *ad; 
    112113    StructDeclaration *sd; 
    113114    ClassDeclaration *cd; 
    114115    InterfaceDeclaration *id; 
    115116    Dsymbol *pd; 
    116117 
    117118#if 0 
    118119    printf("FuncDeclaration::semantic(sc = %p, this = %p, '%s', linkage = %d)\n", sc, this, toPrettyChars(), sc->linkage); 
    119120    if (isFuncLiteralDeclaration()) 
    120121        printf("\tFuncLiteralDeclaration()\n"); 
    121122    printf("sc->parent = %s, parent = %s\n", sc->parent->toChars(), parent ? parent->toChars() : ""); 
    122123    printf("type: %p, %s\n", type, type->toChars()); 
    123124#endif 
    124125 
    125126    if (semanticRun != PASSinit && isFuncLiteralDeclaration()) 
    126127    { 
    127128        /* Member functions that have return types that are 
    128129         * forward references can have semantic() run more than 
    129130         * once on them. 
    130131         * See test\interface2.d, test20 
    131132         */ 
     
    137138 
    138139    if (semanticRun >= PASSsemanticdone) 
    139140    { 
    140141        if (!parent->isClassDeclaration()) 
    141142        { 
    142143            return; 
    143144        } 
    144145        // need to re-run semantic() in order to set the class's vtbl[] 
    145146    } 
    146147    else 
    147148    { 
    148149        assert(semanticRun <= PASSsemantic); 
    149150        semanticRun = PASSsemantic; 
    150151    } 
    151152 
    152153    unsigned dprogress_save = Module::dprogress; 
    153154 
    154155    foverrides.setDim(0);       // reset in case semantic() is being retried for this function 
    155156 
    156157    storage_class |= sc->stc & ~STCref; 
     158    ad = isThis(); 
     159    if (ad) 
     160        storage_class |= ad->storage_class & (STC_TYPECTOR | STCsynchronized); 
     161 
    157162    //printf("function storage_class = x%llx, sc->stc = x%llx, %x\n", storage_class, sc->stc, Declaration::isFinal()); 
    158163 
    159164    if (!originalType) 
    160165        originalType = type; 
    161166    if (!type->deco) 
    162167    { 
    163168        sc = sc->push(); 
    164169        sc->stc |= storage_class & (STCref | STCnothrow | STCpure | STCdisable 
    165170            | STCsafe | STCtrusted | STCsystem);      // forward to function type 
    166171 
    167172        if (isCtorDeclaration()) 
    168173            sc->flags |= SCOPEctor; 
    169174        type = type->semantic(loc, sc); 
    170175        sc = sc->pop(); 
    171176 
    172177        /* Apply const, immutable and shared storage class 
    173178         * to the function type 
    174179         */ 
    175180        StorageClass stc = storage_class; 
    176181        if (type->isImmutable()) 
     
    254259 
    255260    if (isAbstract() && isFinal()) 
    256261        error("cannot be both final and abstract"); 
    257262#if 0 
    258263    if (isAbstract() && fbody) 
    259264        error("abstract functions cannot have bodies"); 
    260265#endif 
    261266 
    262267#if 0 
    263268    if (isStaticConstructor() || isStaticDestructor()) 
    264269    { 
    265270        if (!isStatic() || type->nextOf()->ty != Tvoid) 
    266271            error("static constructors / destructors must be static void"); 
    267272        if (f->arguments && f->arguments->dim) 
    268273            error("static constructors / destructors must have empty parameter list"); 
    269274        // BUG: check for invalid storage classes 
    270275    } 
    271276#endif 
    272277 
    273278#ifdef IN_GCC 
    274     AggregateDeclaration *ad; 
    275  
    276     ad = parent->isAggregateDeclaration(); 
    277     if (ad) 
    278         ad->methods.push(this); 
     279    { 
     280        AggregateDeclaration *ad = parent->isAggregateDeclaration(); 
     281        if (ad) 
     282            ad->methods.push(this); 
     283    } 
    279284#endif 
    280285    sd = parent->isStructDeclaration(); 
    281286    if (sd) 
    282287    { 
    283288        if (isCtorDeclaration()) 
    284289        { 
    285290            goto Ldone; 
    286291        } 
    287292#if 0 
    288293        // Verify no constructors, destructors, etc. 
    289294        if (isCtorDeclaration() 
    290295            //||isDtorDeclaration() 
    291296            //|| isInvariantDeclaration() 
    292297            //|| isUnitTestDeclaration() 
    293298           ) 
    294299        { 
    295300            error("special member functions not allowed for %ss", sd->kind()); 
    296301        } 
    297302 
    298303        if (!sd->inv) 
  • trunk/src/struct.c

    r776 r781  
    355355                        if (ad) 
    356356                            t = ad->handle; 
    357357                        else 
    358358                            t = Type::tvoidptr; 
    359359                    } 
    360360                    else 
    361361                        assert(0); 
    362362                    if (t->ty == Tstruct) 
    363363                        t = Type::tvoidptr;     // t should not be a ref type 
    364364                    assert(!vthis); 
    365365                    vthis = new ThisDeclaration(loc, t); 
    366366                    //vthis->storage_class |= STCref; 
    367367                    members->push(vthis); 
    368368                } 
    369369            } 
    370370        } 
    371371    } 
    372372 
    373373    sizeok = 0; 
    374374    sc2 = sc->push(this); 
    375     sc2->stc &= storage_class & STC_TYPECTOR
     375    sc2->stc &= STCsafe | STCtrusted | STCsystem
    376376    sc2->parent = this; 
    377377    if (isUnionDeclaration()) 
    378378        sc2->inunion = 1; 
    379379    sc2->protection = PROTpublic; 
    380380    sc2->explicitProtection = 0; 
    381381 
    382382    int members_dim = members->dim; 
    383383 
    384384    /* Set scope so if there are forward references, we still might be able to 
    385385     * resolve individual members like enums. 
    386386     */ 
    387387    for (int i = 0; i < members_dim; i++) 
    388388    {   Dsymbol *s = (Dsymbol *)members->data[i]; 
    389389        /* There are problems doing this in the general case because 
    390390         * Scope keeps track of things like 'offset' 
    391391         */ 
    392392        if (s->isEnumDeclaration() || (s->isAggregateDeclaration() && s->ident)) 
    393393        { 
    394394            //printf("setScope %s %s\n", s->kind(), s->toChars()); 
    395395            s->setScope(sc2);