mirror of
https://github.com/ziglang/zig.git
synced 2026-01-21 06:45:24 +00:00
std: non-byte-multiple sized integers have no definite representation
Closes #7445
This commit is contained in:
parent
a471a57560
commit
44556bfebe
@ -481,10 +481,13 @@ pub fn hasUniqueRepresentation(comptime T: type) bool {
|
||||
.Enum,
|
||||
.ErrorSet,
|
||||
.Fn,
|
||||
.Int, // TODO check that it is still true
|
||||
.Pointer,
|
||||
=> return true,
|
||||
|
||||
// The padding bits are undefined.
|
||||
.Int => |info| return (info.bits % 8) == 0 and
|
||||
(info.bits == 0 or std.math.isPowerOfTwo(info.bits)),
|
||||
|
||||
.Array => |info| return comptime hasUniqueRepresentation(info.child),
|
||||
|
||||
.Struct => |info| {
|
||||
@ -525,14 +528,10 @@ test "std.meta.trait.hasUniqueRepresentation" {
|
||||
|
||||
testing.expect(hasUniqueRepresentation(TestStruct3));
|
||||
|
||||
testing.expect(hasUniqueRepresentation(i1));
|
||||
testing.expect(hasUniqueRepresentation(u2));
|
||||
testing.expect(hasUniqueRepresentation(i3));
|
||||
testing.expect(hasUniqueRepresentation(u4));
|
||||
testing.expect(hasUniqueRepresentation(i5));
|
||||
testing.expect(hasUniqueRepresentation(u6));
|
||||
testing.expect(hasUniqueRepresentation(i7));
|
||||
testing.expect(hasUniqueRepresentation(u8));
|
||||
testing.expect(hasUniqueRepresentation(i9));
|
||||
testing.expect(hasUniqueRepresentation(u10));
|
||||
inline for ([_]type{ i0, u8, i16, u32, i64 }) |T| {
|
||||
testing.expect(hasUniqueRepresentation(T));
|
||||
}
|
||||
inline for ([_]type{ i1, u9, i17, u33, i24 }) |T| {
|
||||
testing.expect(!hasUniqueRepresentation(T));
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user