diff --git a/std/experimental/allocator/common.d b/std/experimental/allocator/common.d index 202eb5cd0..862e047d3 100644 --- a/std/experimental/allocator/common.d +++ b/std/experimental/allocator/common.d @@ -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 diff --git a/std/experimental/allocator/package.d b/std/experimental/allocator/package.d index 056ff15b2..8888d387a 100644 --- a/std/experimental/allocator/package.d +++ b/std/experimental/allocator/package.d @@ -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(); }));