Skip to content
Browse files

Issue 2716 - Confusion of auto and scope as the class attribute

  • Loading branch information...
1 parent 254537d commit 3b625d5d22096e8c2b82c779ddc575e04da287eb Walter Bright committed Aug 28, 2010
Showing with 43 additions and 39 deletions.
  1. +1 −1 src/aggregate.h
  2. +6 −4 src/class.c
  3. +1 −1 src/clone.c
  4. +11 −9 src/declaration.c
  5. +3 −3 src/declaration.h
  6. +1 −1 src/expression.c
  7. +2 −2 src/func.c
  8. +12 −12 src/mtype.c
  9. +2 −2 src/mtype.h
  10. +4 −4 src/statement.c
View
2 src/aggregate.h
@@ -223,7 +223,7 @@ struct ClassDeclaration : AggregateDeclaration
TypeInfoClassDeclaration *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 an auto class
int isabstract; // !=0 if abstract class
#if DMDV1
int isnested; // !=0 if is nested
View
10 src/class.c
@@ -196,7 +196,7 @@ ClassDeclaration::ClassDeclaration(Loc loc, Identifier *id, BaseClasses *basecla
}
com = 0;
- isauto = 0;
+ isscope = 0;
isabstract = 0;
inuse = 0;
}
@@ -479,7 +479,7 @@ void ClassDeclaration::semantic(Scope *sc)
// Inherit properties from base class
com = baseClass->isCOMclass();
- isauto = baseClass->isauto;
+ isscope = baseClass->isscope;
vthis = baseClass->vthis;
storage_class |= baseClass->storage_class & STC_TYPECTOR;
}
@@ -563,8 +563,10 @@ void ClassDeclaration::semantic(Scope *sc)
}
}
- if (storage_class & (STCauto | STCscope))
- isauto = 1;
+ if (storage_class & STCauto)
+ error("storage class 'auto' is invalid when declaring a class, did you mean to use 'scope'?");
+ if (storage_class & STCscope)
+ isscope = 1;
if (storage_class & STCabstract)
isabstract = 1;
if (storage_class & STCimmutable)
View
2 src/clone.c
@@ -157,7 +157,7 @@ FuncDeclaration *StructDeclaration::buildOpAssign(Scope *sc)
if (dtor)
{
tmp = new VarDeclaration(0, type, idtmp, new VoidInitializer(0));
- tmp->noauto = 1;
+ tmp->noscope = 1;
tmp->storage_class |= STCctfe;
e = new DeclarationExp(0, tmp);
ec = new AssignExp(0,
View
20 src/declaration.c
@@ -652,7 +652,7 @@ VarDeclaration::VarDeclaration(Loc loc, Type *type, Identifier *id, Initializer
#endif
this->loc = loc;
offset = 0;
- noauto = 0;
+ noscope = 0;
#if DMDV2
isargptr = FALSE;
#endif
@@ -824,6 +824,8 @@ void VarDeclaration::semantic(Scope *sc)
error("no definition of struct %s", ts->toChars());
}
}
+ if ((storage_class & STCauto) && !inferred)
+ error("storage class 'auto' has no effect if type is not inferred, did you mean 'scope'?");
if (tb->ty == Ttuple)
{ /* Instead, declare variables for each of the tuple elements
@@ -975,14 +977,14 @@ void VarDeclaration::semantic(Scope *sc)
}
#endif
- if (type->isauto() && !noauto)
+ if (type->isscope() && !noscope)
{
if (storage_class & (STCfield | STCout | STCref | STCstatic | STCmanifest | STCtls | STCgshared) || !fd)
{
error("globals, statics, fields, manifest constants, 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");
@@ -1590,7 +1592,7 @@ int VarDeclaration::needsAutoDtor()
{
//printf("VarDeclaration::needsAutoDtor() %s\n", toChars());
- if (noauto || storage_class & STCnodtor)
+ if (noscope || storage_class & STCnodtor)
return FALSE;
// Destructors for structs and arrays of structs
@@ -1617,16 +1619,16 @@ int VarDeclaration::needsAutoDtor()
/******************************************
- * If a variable has an auto destructor call, return call for it.
+ * If a variable has a scope destructor call, return call for it.
* Otherwise, return NULL.
*/
-Expression *VarDeclaration::callAutoDtor(Scope *sc)
+Expression *VarDeclaration::callScopeDtor(Scope *sc)
{ Expression *e = NULL;
- //printf("VarDeclaration::callAutoDtor() %s\n", toChars());
+ //printf("VarDeclaration::callScopeDtor() %s\n", toChars());
- if (noauto || storage_class & STCnodtor)
+ if (noscope || storage_class & STCnodtor)
return NULL;
// Destructors for structs and arrays of structs
@@ -1897,7 +1899,7 @@ TypeInfoTupleDeclaration::TypeInfoTupleDeclaration(Type *tinfo)
ThisDeclaration::ThisDeclaration(Loc loc, Type *t)
: VarDeclaration(loc, t, Id::This, NULL)
{
- noauto = 1;
+ noscope = 1;
}
Dsymbol *ThisDeclaration::syntaxCopy(Dsymbol *s)
View
6 src/declaration.h
@@ -140,7 +140,7 @@ struct Declaration : Dsymbol
int isConst() { return storage_class & STCconst; }
int isImmutable() { return storage_class & STCimmutable; }
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; }
@@ -239,7 +239,7 @@ struct VarDeclaration : Declaration
{
Initializer *init;
unsigned offset;
- int noauto; // no auto semantics
+ int noscope; // no auto semantics
#if DMDV2
FuncDeclarations nestedrefs; // referenced by these lexically nested functions
bool isargptr; // if parameter that _argptr points to
@@ -279,7 +279,7 @@ struct VarDeclaration : Declaration
int canTakeAddressOf();
int needsAutoDtor();
#endif
- Expression *callAutoDtor(Scope *sc);
+ Expression *callScopeDtor(Scope *sc);
ExpInitializer *getExpInitializer();
Expression *getConstInitializer();
void checkCtorConstInit();
View
2 src/expression.c
@@ -4341,7 +4341,7 @@ void VarExp::checkEscape()
// if reference type
if (tb->ty == Tarray || tb->ty == Tsarray || tb->ty == Tclass)
{
- if ((v->isAuto() || v->isScope()) && !v->noauto)
+ 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());
View
4 src/func.c
@@ -1107,7 +1107,7 @@ void FuncDeclaration::semantic3(Scope *sc)
loc = fensure->loc;
VarDeclaration *v = new VarDeclaration(loc, type->nextOf(), outId, NULL);
- v->noauto = 1;
+ v->noscope = 1;
v->storage_class |= STCresult;
#if DMDV2
if (!isVirtual())
@@ -1518,7 +1518,7 @@ void FuncDeclaration::semantic3(Scope *sc)
if (v->type->toBasetype()->ty == Tsarray)
continue;
- Expression *e = v->callAutoDtor(sc2);
+ Expression *e = v->callScopeDtor(sc2);
if (e)
{ Statement *s = new ExpStatement(0, e);
s = s->semantic(sc2);
View
24 src/mtype.c
@@ -1576,7 +1576,7 @@ ClassDeclaration *Type::isClassHandle()
return NULL;
}
-int Type::isauto()
+int Type::isscope()
{
return FALSE;
}
@@ -3397,8 +3397,8 @@ Type *TypeSArray::semantic(Loc loc, Scope *sc)
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();
}
@@ -3626,8 +3626,8 @@ Type *TypeDArray::semantic(Loc loc, Scope *sc)
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());
next = tn;
transitive();
@@ -3829,8 +3829,8 @@ Type *TypeNewArray::semantic(Loc loc, Scope *sc)
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());
next = tn;
transitive();
@@ -3957,8 +3957,8 @@ printf("index->ito->ito = x%x\n", index->ito->ito);
error(loc, "can't have associative array of %s", next->toChars());
return Type::terror;
}
- 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 Type::terror;
}
return merge();
@@ -4857,7 +4857,7 @@ Type *TypeFunction::semantic(Loc loc, Scope *sc)
{ error(loc, "functions cannot return a tuple");
tf->next = Type::terror;
}
- if (tf->next->isauto() && !(sc->flags & SCOPEctor))
+ if (tf->next->isscope() && !(sc->flags & SCOPEctor))
error(loc, "functions cannot return scope %s", tf->next->toChars());
if (tf->next->toBasetype()->ty == Tvoid)
tf->isref = FALSE; // rewrite "ref void" as just "void"
@@ -7419,9 +7419,9 @@ ClassDeclaration *TypeClass::isClassHandle()
return sym;
}
-int TypeClass::isauto()
+int TypeClass::isscope()
{
- return sym->isauto;
+ return sym->isscope;
}
int TypeClass::isBaseOf(Type *t, int *poffset)
View
4 src/mtype.h
@@ -246,7 +246,7 @@ struct Type : Object
virtual int iscomplex();
virtual int isscalar();
virtual int isunsigned();
- virtual int isauto();
+ virtual int isscope();
virtual int isString();
virtual int isAssignable();
virtual int checkBoolean(); // if can be converted to boolean value
@@ -814,7 +814,7 @@ struct TypeClass : Type
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();
View
8 src/statement.c
@@ -386,7 +386,7 @@ void DeclarationStatement::scopeCode(Scope *sc, Statement **sentry, Statement **
if (v)
{ Expression *e;
- e = v->callAutoDtor(sc);
+ e = v->callScopeDtor(sc);
if (e)
{
//printf("dtor is: "); e->print();
@@ -1760,7 +1760,7 @@ Statement *ForeachStatement::semantic(Scope *sc)
if (!sc->func->vresult && tret && tret != Type::tvoid)
{
VarDeclaration *v = new VarDeclaration(loc, tret, Id::result, NULL);
- v->noauto = 1;
+ v->noscope = 1;
v->semantic(sc);
if (!sc->insert(v))
assert(0);
@@ -2340,7 +2340,7 @@ Statement *IfStatement::semantic(Scope *sc)
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);
@@ -3496,7 +3496,7 @@ Statement *ReturnStatement::semantic(Scope *sc)
if (!fd->vresult)
{ // Declare vresult
VarDeclaration *v = new VarDeclaration(loc, tret, Id::result, NULL);
- v->noauto = 1;
+ v->noscope = 1;
v->storage_class |= STCresult;
v->semantic(scx);
if (!scx->insert(v))

0 comments on commit 3b625d5

Please sign in to comment.
Something went wrong with that request. Please try again.