# HG changeset patch # User Christian Kamm # Date 1247408121 -7200 # Node ID 05c235309d6f7691f28a6df82d38a2a6efd94fd8 # Parent ad7f2f1862d6bffc280ea434deb05b24bc7adc79 Make the auto storage class never have the same meaning as scope. This changes the meaning of auto class MyClass {} and auto MyClass ident; Both have been made an error to prevent accidents. diff -r ad7f2f1862d6 -r 05c235309d6f dmd/aggregate.h --- a/dmd/aggregate.h Fri Jul 10 21:30:02 2009 +0200 +++ b/dmd/aggregate.h Sun Jul 12 16:15:21 2009 +0200 @@ -222,7 +222,7 @@ ClassInfoDeclaration *vclassinfo; // the ClassInfo object for this ClassDeclaration int com; // !=0 if this is a COM class (meaning // it derives from IUnknown) - int isauto; // !=0 if this is an auto class + int isscope; // !=0 if this is a scope class int isabstract; // !=0 if abstract class int isnested; // !=0 if is nested diff -r ad7f2f1862d6 -r 05c235309d6f dmd/class.c --- a/dmd/class.c Fri Jul 10 21:30:02 2009 +0200 +++ b/dmd/class.c Sun Jul 12 16:15:21 2009 +0200 @@ -184,7 +184,7 @@ } com = 0; - isauto = 0; + isscope = 0; isabstract = 0; isnested = 0; vthis = NULL; @@ -447,7 +447,7 @@ // Inherit properties from base class com = baseClass->isCOMclass(); - isauto = baseClass->isauto; + isscope = baseClass->isscope; vthis = baseClass->vthis; } else @@ -529,8 +529,10 @@ } } - if (storage_class & (STCauto | STCscope)) - isauto = 1; + if (storage_class & STCauto) + error("storage class has no effect: auto"); + if (storage_class & STCscope) + isscope = 1; if (storage_class & STCabstract) isabstract = 1; diff -r ad7f2f1862d6 -r 05c235309d6f dmd/declaration.c --- a/dmd/declaration.c Fri Jul 10 21:30:02 2009 +0200 +++ b/dmd/declaration.c Sun Jul 12 16:15:21 2009 +0200 @@ -619,7 +619,7 @@ #endif this->loc = loc; offset = 0; - noauto = 0; + noscope = 0; nestedref = 0; ctorinit = 0; aliassym = NULL; @@ -747,6 +747,8 @@ error("no definition of struct %s", ts->toChars()); } } + if ((storage_class & STCauto) && !inferred) + error("storage class has no effect: auto"); if (tb->ty == Ttuple) { /* Instead, declare variables for each of the tuple elements @@ -862,14 +864,14 @@ } } - if (type->isauto() && !noauto) + if (type->isscope() && !noscope) { if (storage_class & (STCfield | STCout | STCref | STCstatic) || !fd) { - error("globals, statics, fields, ref and out parameters cannot be auto"); + error("globals, statics, fields, ref and out parameters cannot be scope"); } - if (!(storage_class & (STCauto | STCscope))) + if (!(storage_class & STCscope)) { if (!(storage_class & STCparameter) && ident != Id::withSym) error("reference to scope class must be scope"); @@ -1222,15 +1224,15 @@ } /****************************************** - * If a variable has an auto destructor call, return call for it. + * If a variable has an scope destructor call, return call for it. * Otherwise, return NULL. */ -Expression *VarDeclaration::callAutoDtor() +Expression *VarDeclaration::callScopeDtor() { Expression *e = NULL; - //printf("VarDeclaration::callAutoDtor() %s\n", toChars()); - if (storage_class & (STCauto | STCscope) && !noauto) + //printf("VarDeclaration::callScopeDtor() %s\n", toChars()); + if (storage_class & STCscope && !noscope) { for (ClassDeclaration *cd = type->isClassHandle(); cd; @@ -1430,7 +1432,7 @@ ThisDeclaration::ThisDeclaration(Loc loc, Type *t) : VarDeclaration(loc, t, Id::This, NULL) { - noauto = 1; + noscope = 1; } Dsymbol *ThisDeclaration::syntaxCopy(Dsymbol *s) diff -r ad7f2f1862d6 -r 05c235309d6f dmd/declaration.h --- a/dmd/declaration.h Fri Jul 10 21:30:02 2009 +0200 +++ b/dmd/declaration.h Sun Jul 12 16:15:21 2009 +0200 @@ -130,7 +130,7 @@ int isConst() { return storage_class & STCconst; } int isInvariant() { return 0; } int isAuto() { return storage_class & STCauto; } - int isScope() { return storage_class & (STCscope | STCauto); } + int isScope() { return storage_class & STCscope; } int isSynchronized() { return storage_class & STCsynchronized; } int isParameter() { return storage_class & STCparameter; } int isDeprecated() { return storage_class & STCdeprecated; } @@ -254,7 +254,7 @@ { Initializer *init; unsigned offset; - int noauto; // no auto semantics + int noscope; // no scope semantics int nestedref; // referenced by a lexically nested function int ctorinit; // it has been initialized in a ctor int onstack; // 1: it has been allocated on the stack @@ -279,7 +279,7 @@ int isImportedSymbol(); int isDataseg(); int hasPointers(); - Expression *callAutoDtor(); + Expression *callScopeDtor(); ExpInitializer *getExpInitializer(); void checkCtorConstInit(); void checkNestedReference(Scope *sc, Loc loc); diff -r ad7f2f1862d6 -r 05c235309d6f dmd/expression.c --- a/dmd/expression.c Fri Jul 10 21:30:02 2009 +0200 +++ b/dmd/expression.c Sun Jul 12 16:15:21 2009 +0200 @@ -3993,8 +3993,8 @@ // if reference type if (tb->ty == Tarray || tb->ty == Tsarray || tb->ty == Tclass) { - if ((v->isAuto() || v->isScope()) && !v->noauto) - error("escaping reference to auto local %s", v->toChars()); + if (v->isScope() && !v->noscope) + error("escaping reference to scope local %s", v->toChars()); else if (v->storage_class & STCvariadic) error("escaping reference to variadic parameter %s", v->toChars()); } diff -r ad7f2f1862d6 -r 05c235309d6f dmd/func.c --- a/dmd/func.c Fri Jul 10 21:30:02 2009 +0200 +++ b/dmd/func.c Sun Jul 12 16:15:21 2009 +0200 @@ -184,7 +184,7 @@ error("_ctor is reserved for constructors"); if (isConst() || isAuto() || isScope()) - error("functions cannot be const or auto"); + error("functions cannot be const, auto or scope"); if (isAbstract() && !isVirtual()) error("non-virtual functions cannot be abstract"); @@ -960,7 +960,7 @@ loc = fensure->loc; v = new VarDeclaration(loc, type->nextOf(), outId, NULL); - v->noauto = 1; + v->noscope = 1; sc2->incontract--; v->semantic(sc2); sc2->incontract++; diff -r ad7f2f1862d6 -r 05c235309d6f dmd/mtype.c --- a/dmd/mtype.c Fri Jul 10 21:30:02 2009 +0200 +++ b/dmd/mtype.c Sun Jul 12 16:15:21 2009 +0200 @@ -548,7 +548,7 @@ return NULL; } -int Type::isauto() +int Type::isscope() { return FALSE; } @@ -1996,8 +1996,8 @@ tbn = next = tint32; break; } - if (tbn->isauto()) - error(loc, "cannot have array of auto %s", tbn->toChars()); + if (tbn->isscope()) + error(loc, "cannot have array of scope %s", tbn->toChars()); return merge(); } @@ -2159,8 +2159,8 @@ tn = next = tint32; break; } - if (tn->isauto()) - error(loc, "cannot have array of auto %s", tn->toChars()); + if (tn->isscope()) + error(loc, "cannot have array of scope %s", tn->toChars()); if (next != tn) //deco = NULL; // redo return tn->arrayOf(); @@ -2358,8 +2358,8 @@ error(loc, "can't have associative array of %s", next->toChars()); break; } - if (next->isauto()) - error(loc, "cannot have array of auto %s", next->toChars()); + if (next->isscope()) + error(loc, "cannot have array of scope %s", next->toChars()); return merge(); } @@ -2996,8 +2996,8 @@ { error(loc, "functions cannot return a tuple"); tf->next = Type::terror; } - if (tf->next->isauto() && !(sc->flags & SCOPEctor)) - error(loc, "functions cannot return auto %s", tf->next->toChars()); + if (tf->next->isscope() && !(sc->flags & SCOPEctor)) + error(loc, "functions cannot return scope %s", tf->next->toChars()); if (tf->parameters) { size_t dim = Argument::dim(tf->parameters); @@ -5068,9 +5068,9 @@ return sym; } -int TypeClass::isauto() -{ - return sym->isauto; +int TypeClass::isscope() +{ + return sym->isscope; } int TypeClass::isBaseOf(Type *t, int *poffset) diff -r ad7f2f1862d6 -r 05c235309d6f dmd/mtype.h --- a/dmd/mtype.h Fri Jul 10 21:30:02 2009 +0200 +++ b/dmd/mtype.h Sun Jul 12 16:15:21 2009 +0200 @@ -234,7 +234,7 @@ virtual int iscomplex(); virtual int isscalar(); virtual int isunsigned(); - virtual int isauto(); + virtual int isscope(); virtual int isString(); virtual int checkBoolean(); // if can be converted to boolean value void checkDeprecated(Loc loc, Scope *sc); @@ -692,7 +692,7 @@ Expression *defaultInit(Loc loc); int isZeroInit(Loc loc); MATCH deduceType(Scope *sc, Type *tparam, TemplateParameters *parameters, Objects *dedtypes); - int isauto(); + int isscope(); int checkBoolean(); TypeInfoDeclaration *getTypeInfoDeclaration(); int hasPointers(); diff -r ad7f2f1862d6 -r 05c235309d6f dmd/statement.c --- a/dmd/statement.c Fri Jul 10 21:30:02 2009 +0200 +++ b/dmd/statement.c Sun Jul 12 16:15:21 2009 +0200 @@ -333,7 +333,7 @@ if (v) { Expression *e; - e = v->callAutoDtor(); + e = v->callScopeDtor(); if (e) { //printf("dtor is: "); e->print(); @@ -1590,7 +1590,7 @@ { VarDeclaration *v; v = new VarDeclaration(loc, tret, Id::result, NULL); - v->noauto = 1; + v->noscope = 1; v->semantic(sc); if (!sc->insert(v)) assert(0); @@ -1961,7 +1961,7 @@ Type *t = arg->type ? arg->type : condition->type; match = new VarDeclaration(loc, t, arg->ident, NULL); - match->noauto = 1; + match->noscope = 1; match->semantic(scd); if (!scd->insert(match)) assert(0); @@ -2931,7 +2931,7 @@ if (!fd->vresult) { // Declare vresult VarDeclaration *v = new VarDeclaration(loc, tret, Id::result, NULL); - v->noauto = 1; + v->noscope = 1; v->semantic(scx); if (!scx->insert(v)) assert(0);