authorgravatar for emekankurumeh@outlook.comEmeka Nkurumeh <emekankurumeh@outlook.com> 2019-10-16 17:15:52-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-10-16 18:15:52-04:00
log700bb19a9053e236df6a9f15d435c427391e3ecf
tree2a968a224e481e62dbf0ffc30dc87d30753532a2
parent45e5841281e0adf7924f0931dff219bf38f74622

fix std.mem.AsBytesReturnType (#3442)

closes #3334

1 files changed, 10 insertions(+), 0 deletions(-)

lib/std/mem.zig+10
......@@ -1325,6 +1325,12 @@ fn AsBytesReturnType(comptime P: type) type {
13251325 const size = usize(@sizeOf(meta.Child(P)));
13261326 const alignment = comptime meta.alignment(P);
13271327
1328 if (alignment == 0) {
1329 if (comptime trait.isConstPtr(P))
1330 return *const [size]u8;
1331 return *[size]u8;
1332 }
1333
13281334 if (comptime trait.isConstPtr(P))
13291335 return *align(alignment) const [size]u8;
13301336 return *align(alignment) [size]u8;
......@@ -1364,6 +1370,10 @@ test "asBytes" {
13641370 .d = 0xA1,
13651371 };
13661372 testing.expect(eql(u8, asBytes(&inst), "\xBE\xEF\xDE\xA1"));
1373
1374 const ZST = struct {};
1375 const zero = ZST{};
1376 testing.expect(eql(u8, asBytes(&zero), ""));
13671377}
13681378
13691379///Given any value, returns a copy of its bytes in an array.