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

Commit

Permalink
fix Issue 13809 - dup no longer works with types with postblit and de…
Browse files Browse the repository at this point in the history
…structors

- nested function literal is also assumed to be pure
  therefor the compiler complains about an impure destructor

- move the typeof to a separate _PostBlitType template
  as we only use it to get the postblit attributes
  • Loading branch information
MartinNowak committed Dec 2, 2014
1 parent cad0f1d commit 949e734
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
20 changes: 11 additions & 9 deletions src/object.di
Expand Up @@ -741,26 +741,28 @@ private inout(T)[] _rawDup(T)(inout(T)[] a)
return *cast(inout(T)[]*)&arr;
}

template _PostBlitType(T)
{
// assume that ref T and void* are equivalent in abi level.
static if (is(T == struct))
alias _PostBlitType = typeof(function (ref T t){ T a = t; });
else
alias _PostBlitType = typeof(delegate (ref T t){ T a = t; });
}

// Returns null, or a delegate to call postblit of T
private auto _getPostblit(T)() @trusted pure nothrow @nogc
{
// infer static postblit type, run postblit if any
static if (is(T == struct))
{
import core.internal.traits : Unqual;

// assume that ref T and void* are equivalent in abi level.
alias PostBlitT = typeof(function (ref T t){ T a = t; });

// use typeid(Unqual!T) here to skip TypeInfo_Const/Shared/...
return cast(PostBlitT)typeid(Unqual!T).xpostblit;
return cast(_PostBlitType!T)typeid(Unqual!T).xpostblit;
}
else if ((&typeid(T).postblit).funcptr !is &TypeInfo.postblit)
{
// assume that ref T and void* are equivalent in abi level.
alias PostBlitT = typeof(delegate (ref T t){ T a = t; });

return cast(PostBlitT)&typeid(T).postblit;
return cast(_PostBlitType!T)&typeid(T).postblit;
}
else
return null;
Expand Down
20 changes: 11 additions & 9 deletions src/object_.d
Expand Up @@ -2964,26 +2964,28 @@ private inout(T)[] _rawDup(T)(inout(T)[] a)
return *cast(inout(T)[]*)&arr;
}

template _PostBlitType(T)
{
// assume that ref T and void* are equivalent in abi level.
static if (is(T == struct))
alias _PostBlitType = typeof(function (ref T t){ T a = t; });
else
alias _PostBlitType = typeof(delegate (ref T t){ T a = t; });
}

// Returns null, or a delegate to call postblit of T
private auto _getPostblit(T)() @trusted pure nothrow @nogc
{
// infer static postblit type, run postblit if any
static if (is(T == struct))
{
import core.internal.traits : Unqual;

// assume that ref T and void* are equivalent in abi level.
alias PostBlitT = typeof(function (ref T t){ T a = t; });

// use typeid(Unqual!T) here to skip TypeInfo_Const/Shared/...
return cast(PostBlitT)typeid(Unqual!T).xpostblit;
return cast(_PostBlitType!T)typeid(Unqual!T).xpostblit;
}
else if ((&typeid(T).postblit).funcptr !is &TypeInfo.postblit)
{
// assume that ref T and void* are equivalent in abi level.
alias PostBlitT = typeof(delegate (ref T t){ T a = t; });

return cast(PostBlitT)&typeid(T).postblit;
return cast(_PostBlitType!T)&typeid(T).postblit;
}
else
return null;
Expand Down

0 comments on commit 949e734

Please sign in to comment.