aboutsummaryrefslogtreecommitdiff
path: root/lib/std/meta
diff options
context:
space:
mode:
authorLemonBoy <thatlemon@gmail.com>2020-12-14 18:59:24 +0100
committerLemonBoy <thatlemon@gmail.com>2020-12-14 20:06:46 +0100
commit44556bfebe8d06133c4dfc3cc2685ecb9d3babcd (patch)
treecb9ef3956b26fdc14b85da6efa623325aaca9e6a /lib/std/meta
parenta471a57560401c5562c4dc3e588227b689bf9487 (diff)
downloadzig-44556bfebe8d06133c4dfc3cc2685ecb9d3babcd.tar.gz
zig-44556bfebe8d06133c4dfc3cc2685ecb9d3babcd.zip
std: non-byte-multiple sized integers have no definite representation
Closes #7445
Diffstat (limited to 'lib/std/meta')
-rw-r--r--lib/std/meta/trait.zig21
1 files changed, 10 insertions, 11 deletions
diff --git a/lib/std/meta/trait.zig b/lib/std/meta/trait.zig
index eb294a857c..1656a93798 100644
--- a/lib/std/meta/trait.zig
+++ b/lib/std/meta/trait.zig
@@ -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));
+ }
}