Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
deprecate mutating assignment to ModuleInfo
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
MartinNowak committed Jul 22, 2014
1 parent d9df5c6 commit 2315b7a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
11 changes: 11 additions & 0 deletions src/object.di
Expand Up @@ -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;
Expand Down
21 changes: 11 additions & 10 deletions src/object_.d
Expand Up @@ -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
Expand Down Expand Up @@ -1734,16 +1745,6 @@ const:
}
}

unittest
{
ModuleInfo mi;
foreach (m; ModuleInfo)
{
mi = *m;
break;
}
}

unittest
{
ModuleInfo* m1;
Expand Down
7 changes: 6 additions & 1 deletion src/rt/minfo.d
Expand Up @@ -392,6 +392,11 @@ unittest

static struct UTModuleInfo
{
this(uint flags)
{
mi._flags = flags;
}

void setImports(immutable(ModuleInfo)*[] imports...)
{
import core.bitop;
Expand All @@ -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;
Expand Down

0 comments on commit 2315b7a

Please sign in to comment.