aboutsummaryrefslogtreecommitdiff
path: root/lib/std/meta.zig
diff options
context:
space:
mode:
authorJacob Young <jacobly0@users.noreply.github.com>2024-03-16 16:46:45 +0100
committerJacob Young <jacobly0@users.noreply.github.com>2024-03-17 03:06:17 +0100
commitd10c52c194a093f58df40bc6122f24380f0cc097 (patch)
tree98909ac98dabdf19d082ce94dddf11a54cc11926 /lib/std/meta.zig
parentf88a971e4ff211b78695609b4482fb886f30a1af (diff)
downloadzig-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 'lib/std/meta.zig')
-rw-r--r--lib/std/meta.zig9
1 files changed, 4 insertions, 5 deletions
diff --git a/lib/std/meta.zig b/lib/std/meta.zig
index f7b418d71d..da0f629748 100644
--- a/lib/std/meta.zig
+++ b/lib/std/meta.zig
@@ -57,10 +57,9 @@ test stringToEnum {
}
/// Returns the alignment of type T.
-/// Note that if T is a pointer or function type the result is different than
-/// the one returned by @alignOf(T).
+/// Note that if T is a pointer type the result is different than the one
+/// returned by @alignOf(T).
/// If T is a pointer type the alignment of the type it points to is returned.
-/// If T is a function type the alignment a target-dependent value is returned.
pub fn alignment(comptime T: type) comptime_int {
return switch (@typeInfo(T)) {
.Optional => |info| switch (@typeInfo(info.child)) {
@@ -68,7 +67,6 @@ pub fn alignment(comptime T: type) comptime_int {
else => @alignOf(T),
},
.Pointer => |info| info.alignment,
- .Fn => |info| info.alignment,
else => @alignOf(T),
};
}
@@ -80,7 +78,8 @@ test alignment {
try testing.expect(alignment([]align(1) u8) == 1);
try testing.expect(alignment([]align(2) u8) == 2);
try testing.expect(alignment(fn () void) > 0);
- try testing.expect(alignment(fn () align(128) void) == 128);
+ try testing.expect(alignment(*const fn () void) > 0);
+ try testing.expect(alignment(*align(128) const fn () void) == 128);
}
/// Given a parameterized type (array, vector, pointer, optional), returns the "child type".