diff options
| author | Jacob Young <jacobly0@users.noreply.github.com> | 2024-03-16 16:46:45 +0100 |
|---|---|---|
| committer | Jacob Young <jacobly0@users.noreply.github.com> | 2024-03-17 03:06:17 +0100 |
| commit | d10c52c194a093f58df40bc6122f24380f0cc097 (patch) | |
| tree | 98909ac98dabdf19d082ce94dddf11a54cc11926 /test/cases/compile_errors/function_ptr_alignment.zig | |
| parent | f88a971e4ff211b78695609b4482fb886f30a1af (diff) | |
| download | zig-d10c52c194a093f58df40bc6122f24380f0cc097.tar.gz zig-d10c52c194a093f58df40bc6122f24380f0cc097.zip | |
AstGen: disallow alignment on function types
A pointer type already has an alignment, so this information does not
need to be duplicated on the function type. This already has precedence
with addrspace which is already disallowed on function types for this
reason. Also fixes `@TypeOf(&func)` to have the correct addrspace and
alignment.
Diffstat (limited to 'test/cases/compile_errors/function_ptr_alignment.zig')
| -rw-r--r-- | test/cases/compile_errors/function_ptr_alignment.zig | 28 |
1 files changed, 8 insertions, 20 deletions
diff --git a/test/cases/compile_errors/function_ptr_alignment.zig b/test/cases/compile_errors/function_ptr_alignment.zig index 995ef8d9b1..cf97e61f40 100644 --- a/test/cases/compile_errors/function_ptr_alignment.zig +++ b/test/cases/compile_errors/function_ptr_alignment.zig @@ -1,28 +1,16 @@ -comptime { - var a: *align(2) @TypeOf(foo) = undefined; - _ = &a; -} -fn foo() void {} +fn align1() align(1) void {} +fn align2() align(2) void {} comptime { - var a: *align(1) fn () void = undefined; - _ = &a; -} -comptime { - var a: *align(2) fn () align(2) void = undefined; - _ = &a; -} -comptime { - var a: *align(2) fn () void = undefined; - _ = &a; -} -comptime { - var a: *align(1) fn () align(2) void = undefined; - _ = &a; + _ = @as(*align(1) const fn () void, &align2); + _ = @as(*align(1) const fn () void, &align1); + _ = @as(*align(2) const fn () void, &align2); + _ = @as(*align(2) const fn () void, &align1); } // error // backend=stage2 // target=native // -// :20:19: error: function pointer alignment disagrees with function alignment +// :8:41: error: expected type '*align(2) const fn () void', found '*const fn () void' +// :8:41: note: pointer alignment '1' cannot cast into pointer alignment '2' |
