diff --git a/src/object.di b/src/object.di index f1e6a951013..2d92e873c61 100644 --- a/src/object.di +++ b/src/object.di @@ -279,6 +279,17 @@ struct ModuleInfo uint _flags; uint _index; + version (all) + { + deprecated("ModuleInfo cannot be copy-assigned because it is a variable-sized struct.") + void opAssign(in ModuleInfo m) { _flags = m._flags; _index = m._index; } + } + else + { + @disable this(); + @disable this(this) const; + } + const: @property uint index() nothrow pure; @property uint flags() nothrow pure; @@ -293,7 +304,7 @@ const: @property TypeInfo_Class[] localClasses() nothrow pure; @property string name() nothrow pure; - static int opApply(scope int delegate(immutable(ModuleInfo*)) dg); + static int opApply(scope int delegate(ModuleInfo*) dg); } class Throwable : Object diff --git a/src/object_.d b/src/object_.d index 09f8e86fe29..f8770794da4 100644 --- a/src/object_.d +++ b/src/object_.d @@ -1591,6 +1591,17 @@ struct ModuleInfo uint _flags; uint _index; // index into _moduleinfo_array[] + version (all) + { + deprecated("ModuleInfo cannot be copy-assigned because it is a variable-sized struct.") + void opAssign(in ModuleInfo m) { _flags = m._flags; _index = m._index; } + } + else + { + @disable this(); + @disable this(this) const; + } + const: private void* addrOf(int flag) nothrow pure in @@ -1724,20 +1735,21 @@ const: // return null; } - static int opApply(scope int delegate(immutable(ModuleInfo*)) dg) + static int opApply(scope int delegate(ModuleInfo*) dg) { import rt.minfo; - return rt.minfo.moduleinfos_apply(dg); + // Bugzilla 13084 - enforcing immutable ModuleInfo would break client code + return rt.minfo.moduleinfos_apply( + (immutable(ModuleInfo*)m) => dg(cast(ModuleInfo*)m)); } } unittest { - ModuleInfo mi; + ModuleInfo* m1; foreach (m; ModuleInfo) { - mi = *m; - break; + m1 = m; } } diff --git a/src/rt/minfo.d b/src/rt/minfo.d index 865130c52da..e185447d5bf 100644 --- a/src/rt/minfo.d +++ b/src/rt/minfo.d @@ -392,6 +392,11 @@ unittest static struct UTModuleInfo { + this(uint flags) + { + mi._flags = flags; + } + void setImports(immutable(ModuleInfo)*[] imports...) { import core.bitop; @@ -413,7 +418,7 @@ unittest static UTModuleInfo mockMI(uint flags) { - auto mi = UTModuleInfo(ModuleInfo(flags | MIimportedModules)); + auto mi = UTModuleInfo(flags | MIimportedModules); auto p = cast(void function()*)&mi.pad; if (flags & MItlsctor) *p++ = &stub; if (flags & MItlsdtor) *p++ = &stub; diff --git a/src/test_runner.d b/src/test_runner.d index 03d19970791..e5c66483ea1 100644 --- a/src/test_runner.d +++ b/src/test_runner.d @@ -1,7 +1,7 @@ import core.runtime, core.time : TickDuration; import core.stdc.stdio; -immutable(ModuleInfo*) getModuleInfo(string name) +ModuleInfo* getModuleInfo(string name) { foreach (m; ModuleInfo) if (m.name == name) return m;