diff --git a/src/core/thread.d b/src/core/thread.d index f1400a3c4f..0b02e262fe 100644 --- a/src/core/thread.d +++ b/src/core/thread.d @@ -1585,7 +1585,7 @@ private: return cast(Mutex)_locks[1].ptr; } - __gshared byte[__traits(classInstanceSize, Mutex)][2] _locks; + __gshared void[__traits(classInstanceSize, Mutex)][2] _locks; static void initLocks() { diff --git a/src/gc/gc.d b/src/gc/gc.d index e1774ac006..29481a5a90 100644 --- a/src/gc/gc.d +++ b/src/gc/gc.d @@ -268,7 +268,7 @@ struct GC // We can't allocate a Mutex on the GC heap because we are the GC. // Store it in the static data segment instead. __gshared GCMutex gcLock; // global lock - __gshared byte[__traits(classInstanceSize, GCMutex)] mutexStorage; + __gshared void[__traits(classInstanceSize, GCMutex)] mutexStorage; __gshared Config config; diff --git a/src/object.di b/src/object.di index 00e4d37d28..f58c9b3c91 100644 --- a/src/object.di +++ b/src/object.di @@ -183,7 +183,7 @@ class TypeInfo_Class : TypeInfo @property auto info() @safe nothrow pure const { return this; } @property auto typeinfo() @safe nothrow pure const { return this; } - byte[] init; // class static initializer + byte[] m_init; // class static initializer string name; // class name void*[] vtbl; // virtual function pointer table Interface[] interfaces; diff --git a/src/object_.d b/src/object_.d index b0395ca1a0..68b130c77a 100644 --- a/src/object_.d +++ b/src/object_.d @@ -824,6 +824,8 @@ class TypeInfo_Class : TypeInfo return Object.sizeof; } + override const(void)[] init() nothrow pure const @safe { return m_init; } + override @property uint flags() nothrow pure const { return 1; } override @property const(OffsetTypeInfo)[] offTi() nothrow pure const @@ -834,7 +836,7 @@ class TypeInfo_Class : TypeInfo @property auto info() @safe nothrow pure const { return this; } @property auto typeinfo() @safe nothrow pure const { return this; } - byte[] init; /** class static initializer + byte[] m_init; /** class static initializer * (init.length gives size in bytes of class) */ string name; /// class name @@ -903,6 +905,20 @@ class TypeInfo_Class : TypeInfo alias TypeInfo_Class ClassInfo; +unittest +{ + // Bugzilla 14401 + static class X + { + int a; + } + + assert(typeid(X).init is typeid(X).m_init); + assert(typeid(X).init.length == typeid(const(X)).init.length); + assert(typeid(X).init.length == typeid(shared(X)).init.length); + assert(typeid(X).init.length == typeid(immutable(X)).init.length); +} + class TypeInfo_Interface : TypeInfo { override string toString() const { return info.name; } diff --git a/src/rt/lifetime.d b/src/rt/lifetime.d index c54a09da53..c8ef1fa8f9 100644 --- a/src/rt/lifetime.d +++ b/src/rt/lifetime.d @@ -112,7 +112,7 @@ extern (C) Object _d_newclass(const ClassInfo ci) } // initialize it - (cast(byte*) p)[0 .. ci.init.length] = ci.init[]; + p[0 .. ci.init.length] = ci.init[]; debug(PRINTF) printf("initialization done\n"); return cast(Object) p; @@ -1412,10 +1412,10 @@ extern (C) void rt_finalize2(void* p, bool det = true, bool resetMemory = true) if (ppv[1]) // if monitor is not null _d_monitordelete(cast(Object) p, det); - if(resetMemory) + if (resetMemory) { - byte[] w = (*pc).init; - (cast(byte*) p)[0 .. w.length] = w[]; + auto w = (*pc).init; + p[0 .. w.length] = w[]; } } catch (Exception e)