mirror of
https://github.com/ziglang/zig.git
synced 2025-12-26 16:13:07 +00:00
Previously, this function would return an incorrect result for structs and unions which did not have their fields resolved yet. This required introducing more logic in Sema to resolve types before doing certain things such as creating an anonmyous Decl and emitting function call AIR. As a result a couple more struct tests pass. Oh, and I implemented the language change to make sizeOf for pointers always return pointer size bytes even if the element type is 0 bits.
19 lines
532 B
Zig
19 lines
532 B
Zig
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_is_stage2) {
|
|
// 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;
|
|
}
|