diff --git a/src/declaration.c b/src/declaration.c index 44ba937e8669..d90312e65ba1 100644 --- a/src/declaration.c +++ b/src/declaration.c @@ -1,6 +1,6 @@ // Compiler implementation of the D programming language -// Copyright (c) 1999-2012 by Digital Mars +// Copyright (c) 1999-2013 by Digital Mars // All Rights Reserved // written by Walter Bright // http://www.digitalmars.com @@ -84,7 +84,7 @@ Declaration::Declaration(Identifier *id) linkage = LINKdefault; inuse = 0; sem = SemanticStart; - mangleOverride = NULL; + mangleOverride = NULL; } void Declaration::semantic(Scope *sc) @@ -1185,7 +1185,7 @@ void VarDeclaration::semantic(Scope *sc) AggregateDeclaration *aad = parent->isAggregateDeclaration(); if (aad) { -#if DMDV2 +#if PULL93 assert(!(storage_class & (STCextern | STCstatic | STCtls | STCgshared))); if (storage_class & (STCconst | STCimmutable) && init && global.params.vfield) @@ -1194,6 +1194,16 @@ void VarDeclaration::semantic(Scope *sc) const char *s = (storage_class & STCimmutable) ? "immutable" : "const"; fprintf(stderr, "%s: %s.%s is %s field\n", p ? p : "", ad->toPrettyChars(), toChars(), s); } +#else + if (storage_class & (STCconst | STCimmutable) && init) + { + StorageClass stc = storage_class & (STCconst | STCimmutable); + warning(loc, "%s field with initializer should be static, __gshared, or an enum", + StorageClassDeclaration::stcToChars(NULL, stc)); + if (!tb->isTypeBasic()) + storage_class |= STCstatic; + } + else #endif { storage_class |= STCfield; @@ -1912,6 +1922,10 @@ AggregateDeclaration *VarDeclaration::isThis() if (!(storage_class & (STCstatic | STCextern | STCmanifest | STCtemplateparameter | STCtls | STCgshared | STCctfe))) { +#if !PULL93 + if ((storage_class & (STCconst | STCimmutable | STCwild)) && init) + return NULL; +#endif for (Dsymbol *s = this; s; s = s->parent) { ad = s->isMember(); diff --git a/src/expression.c b/src/expression.c index e9c283f683af..609683f7a28d 100644 --- a/src/expression.c +++ b/src/expression.c @@ -7498,7 +7498,9 @@ Expression *DotVarExp::semantic(Scope *sc) accessCheck(loc, sc, e1, var); VarDeclaration *v = var->isVarDeclaration(); +#if PULL93 if (v && (v->isDataseg() || (v->storage_class & STCmanifest))) +#endif { Expression *e = expandVar(WANTvalue, v); if (e) diff --git a/src/mars.c b/src/mars.c index d08dbc3d1fcd..e0d5378b42c3 100644 --- a/src/mars.c +++ b/src/mars.c @@ -621,11 +621,18 @@ int tryMain(size_t argc, char *argv[]) { if (strcmp(p + 12, "?") == 0) { +#if PULL93 printf("\ Language changes listed by -transition=id:\n\ =field,3449 do list all non-mutable fields occupies object instance\n\ =tls do list all variables going into thread local storage\n\ "); +#else + printf("\ +Language changes listed by -transition=id:\n\ + =tls do list all variables going into thread local storage\n\ +"); +#endif return EXIT_FAILURE; } if (isdigit((unsigned char)p[12])) @@ -648,8 +655,10 @@ Language changes listed by -transition=id:\n\ { if (strcmp(p + 12, "tls") == 0) global.params.vtls = 1; +#if PULL93 else if (strcmp(p + 12, "field") == 0) global.params.vfield = 1; +#endif } else goto Lerror; diff --git a/src/mars.h b/src/mars.h index ace4638d9509..b6a83d973f72 100644 --- a/src/mars.h +++ b/src/mars.h @@ -88,6 +88,7 @@ void unittests(); #define DMDV2 1 // Version 2.0 features #define SNAN_DEFAULT_INIT DMDV2 // if floats are default initialized to signalling NaN #define MODULEINFO_IS_STRUCT DMDV2 // if ModuleInfo is a struct rather than a class +#define PULL93 0 // controversial pull #93 for bugzilla 3449 // Set if C++ mangling is done by the front end #define CPP_MANGLE (DMDV2 && (TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_OPENBSD || TARGET_SOLARIS)) diff --git a/test/compilable/sw_transition_3449.d b/test/compilable/sw_transition_3449.d deleted file mode 100644 index d2f7704a3dc4..000000000000 --- a/test/compilable/sw_transition_3449.d +++ /dev/null @@ -1,25 +0,0 @@ -// PERMUTE_ARGS: -// REQUIRED_ARGS: -c -transition=3449 -/* -TEST_OUTPUT: ---- -compilable/sw_transition_3449.d(15): sw_transition_3449.S1.ix is immutable field -compilable/sw_transition_3449.d(16): sw_transition_3449.S1.cx is const field -compilable/sw_transition_3449.d(21): sw_transition_3449.S2!(immutable(int)).S2.f is immutable field -compilable/sw_transition_3449.d(21): sw_transition_3449.S2!(const(int)).S2.f is const field ---- -*/ - -struct S1 -{ - immutable int ix = 1; - const int cx = 2; -} - -struct S2(F) -{ - F f = F.init; -} - -alias S2!(immutable int) S2I; -alias S2!( const int) S2C; diff --git a/test/compilable/sw_transition_field.d b/test/compilable/sw_transition_field.d index 83dd2617459c..48bea79d2e9e 100644 --- a/test/compilable/sw_transition_field.d +++ b/test/compilable/sw_transition_field.d @@ -3,6 +3,10 @@ /* TEST_OUTPUT: --- +--- +*/ +/* +--- compilable/sw_transition_field.d(15): sw_transition_field.S1.ix is immutable field compilable/sw_transition_field.d(16): sw_transition_field.S1.cx is const field compilable/sw_transition_field.d(21): sw_transition_field.S2!(immutable(int)).S2.f is immutable field diff --git a/test/runnable/test3449.d b/test/runnable/test3449.d index 4f9988e405b8..4283bcaae0f9 100644 --- a/test/runnable/test3449.d +++ b/test/runnable/test3449.d @@ -1,3 +1,5 @@ +version (PULL93) +{ template TypeTuple(T...) { alias TypeTuple = T; } // If module variable has no explicit initializer, @@ -83,3 +85,8 @@ void main() assert(s2.field2 == 10); } } +} +else +{ + void main() { } +} diff --git a/test/runnable/testconst.d b/test/runnable/testconst.d index 6cb7e91fd705..1049e6aad825 100644 --- a/test/runnable/testconst.d +++ b/test/runnable/testconst.d @@ -533,8 +533,16 @@ struct S40 void test40() { + version (PULL93) + { assert(S40.sizeof == 8); assert(S40.init.b == 3); + } + else + { + assert(S40.sizeof == 4); + assert(S40.b == 3); + } } /************************************/ @@ -566,7 +574,14 @@ class C42 { int a = ctfe() - 2; const int b; + version (PULL93) + { + enum int c = ctfe(); + } + else + { const int c = ctfe(); + } static const int d; static const int e = ctfe() + 2; @@ -584,7 +599,14 @@ class C42 void test42() { printf("%d\n", C42.classinfo.init.length); + version (PULL93) + { assert(C42.classinfo.init.length == 12 + (void*).sizeof + (void*).sizeof); + } + else + { + assert(C42.classinfo.init.length == 8 + (void*).sizeof + (void*).sizeof); + } C42 c = new C42; assert(c.a == 1); assert(c.b == 2); @@ -595,8 +617,11 @@ void test42() const(int)*p; p = &c.b; assert(*p == 2); + version (PULL93) + { p = &c.c; assert(*p == 3); + } p = &c.d; assert(*p == 4); p = &c.e;