master
1const builtin = @import("builtin");
2const std = @import("std");
3const expect = std.testing.expect;
4
5test "switch on empty enum" {
6 const E = enum {};
7 var e: E = undefined;
8 _ = &e;
9 switch (e) {}
10}
11
12test "switch on empty enum with a specified tag type" {
13 const E = enum(u8) {};
14 var e: E = undefined;
15 _ = &e;
16 switch (e) {}
17}
18
19test "switch on empty auto numbered tagged union" {
20 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
21
22 const U = union(enum(u8)) {};
23 var u: U = undefined;
24 _ = &u;
25 switch (u) {}
26}
27
28test "switch on empty tagged union" {
29 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
30
31 const E = enum {};
32 const U = union(E) {};
33 var u: U = undefined;
34 _ = &u;
35 switch (u) {}
36}
37
38test "empty union" {
39 const U = union {};
40 try expect(@sizeOf(U) == 0);
41 try expect(@alignOf(U) == 1);
42}
43
44test "empty extern union" {
45 const U = extern union {};
46 try expect(@sizeOf(U) == 0);
47 try expect(@alignOf(U) == 1);
48}
49
50test "empty union passed as argument" {
51 const U = union(enum) {
52 fn f(u: @This()) void {
53 switch (u) {}
54 }
55 };
56 U.f(@as(U, undefined));
57}
58
59test "empty enum passed as argument" {
60 const E = enum {
61 fn f(e: @This()) void {
62 switch (e) {}
63 }
64 };
65 E.f(@as(E, undefined));
66}