master
1var runtime_int: u32 = 123;
2
3export fn foo() void {
4 comptime var x: u32 = 123;
5 var runtime = &x;
6 _ = &runtime;
7}
8
9export fn bar() void {
10 const S = struct { u32, *const u32 };
11 comptime var x: u32 = 123;
12 const runtime: S = .{ runtime_int, &x };
13 _ = runtime;
14}
15
16export fn qux() void {
17 const S = struct { a: u32, b: *const u32 };
18 comptime var x: u32 = 123;
19 const runtime: S = .{ .a = runtime_int, .b = &x };
20 _ = runtime;
21}
22
23export fn baz() void {
24 const S = struct {
25 fn f(_: *const u32) void {}
26 };
27 comptime var x: u32 = 123;
28 S.f(&x);
29}
30
31export fn faz() void {
32 const S = struct {
33 fn f(_: anytype) void {}
34 };
35 comptime var x: u32 = 123;
36 S.f(&x);
37}
38
39export fn boo() *const u32 {
40 comptime var x: u32 = 123;
41 return &x;
42}
43
44export fn qar() void {
45 comptime var x: u32 = 123;
46 const y = if (runtime_int == 123) &x else undefined;
47 _ = y;
48}
49
50export fn bux() void {
51 comptime var x: [2]u32 = undefined;
52 x = .{ 1, 2 };
53
54 var rt: [2]u32 = undefined;
55 @memcpy(&rt, &x);
56}
57
58export fn far() void {
59 comptime var x: u32 = 123;
60
61 var rt: [2]*u32 = undefined;
62 const elem: *u32 = &x;
63 @memset(&rt, elem);
64}
65
66export fn bax() void {
67 comptime var x: [2]u32 = undefined;
68 x = .{ 1, 2 };
69
70 var rt: [2]u32 = undefined;
71 @memmove(&rt, &x);
72}
73
74// error
75//
76// :5:19: error: runtime value contains reference to comptime var
77// :5:19: note: comptime var pointers are not available at runtime
78// :4:14: note: 'runtime_value' points to comptime var declared here
79// :12:40: error: runtime value contains reference to comptime var
80// :12:40: note: comptime var pointers are not available at runtime
81// :11:14: note: 'runtime_value' points to comptime var declared here
82// :19:50: error: runtime value contains reference to comptime var
83// :19:50: note: comptime var pointers are not available at runtime
84// :18:14: note: 'runtime_value' points to comptime var declared here
85// :28:9: error: runtime value contains reference to comptime var
86// :28:9: note: comptime var pointers are not available at runtime
87// :27:14: note: 'runtime_value' points to comptime var declared here
88// :36:9: error: runtime value contains reference to comptime var
89// :36:9: note: comptime var pointers are not available at runtime
90// :35:14: note: 'runtime_value' points to comptime var declared here
91// :41:12: error: runtime value contains reference to comptime var
92// :41:12: note: comptime var pointers are not available at runtime
93// :40:14: note: 'runtime_value' points to comptime var declared here
94// :46:39: error: runtime value contains reference to comptime var
95// :46:39: note: comptime var pointers are not available at runtime
96// :45:14: note: 'runtime_value' points to comptime var declared here
97// :55:18: error: runtime value contains reference to comptime var
98// :55:18: note: comptime var pointers are not available at runtime
99// :51:14: note: 'runtime_value' points to comptime var declared here
100// :63:18: error: runtime value contains reference to comptime var
101// :63:18: note: comptime var pointers are not available at runtime
102// :59:14: note: 'runtime_value' points to comptime var declared here
103// :71:19: error: runtime value contains reference to comptime var
104// :71:19: note: comptime var pointers are not available at runtime
105// :67:14: note: 'runtime_value' points to comptime var declared here