add compile error for alignCasting zero sized types

This commit is contained in:
Vexu
2020-08-01 22:46:28 +03:00
committed by Andrew Kelley
parent 35391f1709
commit 6bba7c702b
2 changed files with 39 additions and 0 deletions

View File

@@ -2,6 +2,32 @@ const tests = @import("tests.zig");
const std = @import("std");
pub fn addCases(cases: *tests.CompileErrorContext) void {
cases.addTest("@alignCast of zero sized types",
\\export fn foo() void {
\\ const a: *void = undefined;
\\ _ = @alignCast(2, a);
\\}
\\export fn bar() void {
\\ const a: ?*void = undefined;
\\ _ = @alignCast(2, a);
\\}
\\export fn baz() void {
\\ const a: []void = undefined;
\\ _ = @alignCast(2, a);
\\}
\\export fn qux() void {
\\ const a = struct {
\\ fn a(comptime b: u32) void {}
\\ }.a;
\\ _ = @alignCast(2, a);
\\}
, &[_][]const u8{
"tmp.zig:3:23: error: cannot adjust alignment of zero sized type '*void'",
"tmp.zig:7:23: error: cannot adjust alignment of zero sized type '?*void'",
"tmp.zig:11:23: error: cannot adjust alignment of zero sized type '[]void'",
"tmp.zig:17:23: error: cannot adjust alignment of zero sized type 'fn(u32) anytype'",
});
cases.addTest("invalid pointer with @Type",
\\export fn entry() void {
\\ _ = @Type(.{ .Pointer = .{