diff options
| author | Rocknest <35231115+Rocknest@users.noreply.github.com> | 2019-10-17 01:57:29 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-10-17 01:57:29 +0300 |
| commit | 40d53a7bc5ef18607266790e99fa693ba4344645 (patch) | |
| tree | 7e124a713889646e4e55c77e5d70d621fc572e6e /lib/std/mem.zig | |
| parent | c95a9e978582ca96bf5462c6bfdd40b934e9ba92 (diff) | |
| parent | 700bb19a9053e236df6a9f15d435c427391e3ecf (diff) | |
| download | zig-40d53a7bc5ef18607266790e99fa693ba4344645.tar.gz zig-40d53a7bc5ef18607266790e99fa693ba4344645.zip | |
Merge branch 'master' into docs-local
Diffstat (limited to 'lib/std/mem.zig')
| -rw-r--r-- | lib/std/mem.zig | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/std/mem.zig b/lib/std/mem.zig index 2091eb4804..601c50242d 100644 --- a/lib/std/mem.zig +++ b/lib/std/mem.zig @@ -1325,6 +1325,12 @@ fn AsBytesReturnType(comptime P: type) type { const size = usize(@sizeOf(meta.Child(P))); const alignment = comptime meta.alignment(P); + if (alignment == 0) { + if (comptime trait.isConstPtr(P)) + return *const [size]u8; + return *[size]u8; + } + if (comptime trait.isConstPtr(P)) return *align(alignment) const [size]u8; return *align(alignment) [size]u8; @@ -1364,6 +1370,10 @@ test "asBytes" { .d = 0xA1, }; testing.expect(eql(u8, asBytes(&inst), "\xBE\xEF\xDE\xA1")); + + const ZST = struct {}; + const zero = ZST{}; + testing.expect(eql(u8, asBytes(&zero), "")); } ///Given any value, returns a copy of its bytes in an array. |
