blob: 7bab4d347af13377302f5152c13e72aa88743fde (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
const std = @import("std");
test "lazy sizeof comparison with zero" {
const Empty = struct {};
const T = *Empty;
try std.testing.expect(hasNoBits(T));
}
fn hasNoBits(comptime T: type) bool {
if (@import("builtin").zig_backend != .stage1) {
// It is an accepted proposal to make `@sizeOf` for pointers independent
// of whether the element type is zero bits.
// This language change has not been implemented in stage1.
return @sizeOf(T) == @sizeOf(*i32);
}
return @sizeOf(T) == 0;
}
|