Mercurial > projects > ldc
comparison dmd/declaration.c @ 1530:05c235309d6f
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.
author | Christian Kamm <kamm incasoftware de> |
---|---|
date | Sun, 12 Jul 2009 16:15:21 +0200 |
parents | df11cdec45a2 |
children | e4ff2e15cf5f |
comparison
equal
deleted
inserted
replaced
1529:ad7f2f1862d6 | 1530:05c235309d6f |
---|---|
617 this->htype = NULL; | 617 this->htype = NULL; |
618 this->hinit = NULL; | 618 this->hinit = NULL; |
619 #endif | 619 #endif |
620 this->loc = loc; | 620 this->loc = loc; |
621 offset = 0; | 621 offset = 0; |
622 noauto = 0; | 622 noscope = 0; |
623 nestedref = 0; | 623 nestedref = 0; |
624 ctorinit = 0; | 624 ctorinit = 0; |
625 aliassym = NULL; | 625 aliassym = NULL; |
626 onstack = 0; | 626 onstack = 0; |
627 canassign = 0; | 627 canassign = 0; |
745 if (!ts->sym->members) | 745 if (!ts->sym->members) |
746 { | 746 { |
747 error("no definition of struct %s", ts->toChars()); | 747 error("no definition of struct %s", ts->toChars()); |
748 } | 748 } |
749 } | 749 } |
750 if ((storage_class & STCauto) && !inferred) | |
751 error("storage class has no effect: auto"); | |
750 | 752 |
751 if (tb->ty == Ttuple) | 753 if (tb->ty == Ttuple) |
752 { /* Instead, declare variables for each of the tuple elements | 754 { /* Instead, declare variables for each of the tuple elements |
753 * and add those. | 755 * and add those. |
754 */ | 756 */ |
860 error("cannot use template to add field to aggregate '%s'", ad->toChars()); | 862 error("cannot use template to add field to aggregate '%s'", ad->toChars()); |
861 } | 863 } |
862 } | 864 } |
863 } | 865 } |
864 | 866 |
865 if (type->isauto() && !noauto) | 867 if (type->isscope() && !noscope) |
866 { | 868 { |
867 if (storage_class & (STCfield | STCout | STCref | STCstatic) || !fd) | 869 if (storage_class & (STCfield | STCout | STCref | STCstatic) || !fd) |
868 { | 870 { |
869 error("globals, statics, fields, ref and out parameters cannot be auto"); | 871 error("globals, statics, fields, ref and out parameters cannot be scope"); |
870 } | 872 } |
871 | 873 |
872 if (!(storage_class & (STCauto | STCscope))) | 874 if (!(storage_class & STCscope)) |
873 { | 875 { |
874 if (!(storage_class & STCparameter) && ident != Id::withSym) | 876 if (!(storage_class & STCparameter) && ident != Id::withSym) |
875 error("reference to scope class must be scope"); | 877 error("reference to scope class must be scope"); |
876 } | 878 } |
877 } | 879 } |
1220 return 0; | 1222 return 0; |
1221 return isConst(); | 1223 return isConst(); |
1222 } | 1224 } |
1223 | 1225 |
1224 /****************************************** | 1226 /****************************************** |
1225 * If a variable has an auto destructor call, return call for it. | 1227 * If a variable has an scope destructor call, return call for it. |
1226 * Otherwise, return NULL. | 1228 * Otherwise, return NULL. |
1227 */ | 1229 */ |
1228 | 1230 |
1229 Expression *VarDeclaration::callAutoDtor() | 1231 Expression *VarDeclaration::callScopeDtor() |
1230 { Expression *e = NULL; | 1232 { Expression *e = NULL; |
1231 | 1233 |
1232 //printf("VarDeclaration::callAutoDtor() %s\n", toChars()); | 1234 //printf("VarDeclaration::callScopeDtor() %s\n", toChars()); |
1233 if (storage_class & (STCauto | STCscope) && !noauto) | 1235 if (storage_class & STCscope && !noscope) |
1234 { | 1236 { |
1235 for (ClassDeclaration *cd = type->isClassHandle(); | 1237 for (ClassDeclaration *cd = type->isClassHandle(); |
1236 cd; | 1238 cd; |
1237 cd = cd->baseClass) | 1239 cd = cd->baseClass) |
1238 { | 1240 { |
1428 // For the "this" parameter to member functions | 1430 // For the "this" parameter to member functions |
1429 | 1431 |
1430 ThisDeclaration::ThisDeclaration(Loc loc, Type *t) | 1432 ThisDeclaration::ThisDeclaration(Loc loc, Type *t) |
1431 : VarDeclaration(loc, t, Id::This, NULL) | 1433 : VarDeclaration(loc, t, Id::This, NULL) |
1432 { | 1434 { |
1433 noauto = 1; | 1435 noscope = 1; |
1434 } | 1436 } |
1435 | 1437 |
1436 Dsymbol *ThisDeclaration::syntaxCopy(Dsymbol *s) | 1438 Dsymbol *ThisDeclaration::syntaxCopy(Dsymbol *s) |
1437 { | 1439 { |
1438 assert(0); // should never be produced by syntax | 1440 assert(0); // should never be produced by syntax |