master
 1const std = @import("std");
 2const assert = std.debug.assert;
 3const expect = std.testing.expect;
 4const builtin = @import("builtin");
 5const native_arch = builtin.target.cpu.arch;
 6const maxInt = std.math.maxInt;
 7
 8const Foo = struct {
 9    x: u32,
10    y: u32,
11    z: u32,
12};
13
14test "@alignOf(T) before referencing T" {
15    comptime assert(@alignOf(Foo) != maxInt(usize));
16    if (native_arch == .x86_64) {
17        comptime assert(@alignOf(Foo) == 4);
18    }
19}
20
21test "comparison of @alignOf(T) against zero" {
22    const T = struct { x: u32 };
23    try expect(!(@alignOf(T) == 0));
24    try expect(@alignOf(T) != 0);
25    try expect(!(@alignOf(T) < 0));
26    try expect(!(@alignOf(T) <= 0));
27    try expect(@alignOf(T) > 0);
28    try expect(@alignOf(T) >= 0);
29}
30
31test "correct alignment for elements and slices of aligned array" {
32    if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
33
34    var buf: [1024]u8 align(64) = undefined;
35    var start: usize = 1;
36    var end: usize = undefined;
37    _ = .{ &start, &end };
38    try expect(@alignOf(@TypeOf(buf[start..end])) == @alignOf(*u8));
39    try expect(@alignOf(@TypeOf(&buf[start..end])) == @alignOf(*u8));
40    try expect(@alignOf(@TypeOf(&buf[start])) == @alignOf(*u8));
41}