Fix Issue 19085 - std.experimental.allocator.makeArray should work with void

This commit is contained in:
Sebastian Wilzbach 2018-08-16 14:29:03 +02:00 committed by Nathan Sashihara
parent a12d990924
commit 6479a70a3b
2 changed files with 24 additions and 2 deletions

View file

@ -832,6 +832,7 @@ private template isAllZeroBits(T, T value)
else static if (is(typeof(value is 0)))
enum isAllZeroBits = value is 0;
else static if (isStaticArray!(typeof(value)))
{
enum isAllZeroBits = ()
{
@ -846,6 +847,7 @@ private template isAllZeroBits(T, T value)
}
else return false;
}();
}
else static if (is(typeof(value) == struct) || is(typeof(value) == union))
enum isAllZeroBits = ()
{
@ -937,8 +939,10 @@ zero bits? Padding between a struct's fields is not considered.
+/
package template isInitAllZeroBits(T)
{
static if (isStaticArray!T && __traits(compiles, T.init[0]))
enum isInitAllZeroBits = __traits(compiles, {
static if (is(Unqual!T == void))
enum isInitAllZeroBits = true;
else static if (isStaticArray!T && __traits(compiles, T.init[0]))
enum isInitAllZeroBits = is(Unqual!(typeof(T.init[0])) == void) || __traits(compiles, {
static assert(isAllZeroBits!(typeof(T.init[0]), T.init[0]));
});
else
@ -1023,6 +1027,14 @@ package template isInitAllZeroBits(T)
static assert(isInitAllZeroBits!(const(S5)) == isInitAllZeroBits!S5);
}
// https://issues.dlang.org/show_bug.cgi?id=19085
@safe unittest
{
static assert(isInitAllZeroBits!(void[]));
static assert(isInitAllZeroBits!(void[10]));
static assert(isInitAllZeroBits!(void));
}
/+
Can the representation be determined at compile time to consist of nothing but
1 bits? This is reported as $(B false) for structs with padding between

View file

@ -1629,6 +1629,16 @@ T[] makeArray(T, Allocator)(auto ref Allocator alloc, size_t length)
assert(c.equal([0, 0, 0, 0, 0]));
}
// https://issues.dlang.org/show_bug.cgi?id=19085 - makeArray with void
@system unittest
{
auto b = theAllocator.makeArray!void(5);
scope(exit) theAllocator.dispose(b);
auto c = cast(ubyte[]) b;
assert(c.length == 5);
assert(c == [0, 0, 0, 0, 0]); // default initialization
}
private enum hasPurePostblit(T) = !hasElaborateCopyConstructor!T ||
is(typeof(() pure { T.init.__xpostblit(); }));