From 2315b7adba6eb081c46873551f40d0bd20913ca6 Mon Sep 17 00:00:00 2001 From: Martin Nowak Date: Tue, 22 Jul 2014 13:24:33 +0200 Subject: [PATCH] deprecate mutating assignment to ModuleInfo - It's not possible to deprecate default construction as `deprecate this()` is not allowed. - Deprecating copy-construction `deprecate this(this)` results in a lot of false deprecation warnings due to compiler generated functions. --- src/object.di | 11 +++++++++++ src/object_.d | 21 +++++++++++---------- src/rt/minfo.d | 7 ++++++- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/object.di b/src/object.di index 07f67ccaa31..980c5dd2554 100644 --- a/src/object.di +++ b/src/object.di @@ -280,6 +280,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; diff --git a/src/object_.d b/src/object_.d index c886a245c4f..b035bf9b5ae 100644 --- a/src/object_.d +++ b/src/object_.d @@ -1592,6 +1592,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 @@ -1734,16 +1745,6 @@ const: } } -unittest -{ - ModuleInfo mi; - foreach (m; ModuleInfo) - { - mi = *m; - break; - } -} - unittest { ModuleInfo* m1; 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;