authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2022-06-05 13:46:52 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2022-06-05 13:46:52 -07:00
log09a26d4f28ed44334df7fa5a77e3d6c3b016e090
treeaf6a2b7ebed8ad853097fac5c2d6a53696d729bd
parent89bee5bad3c6f0cab3ab87942b5f653cc3d0ac33

ptrCast: add better compile error for accidentally passing 0-size type


1 files changed, 1 insertions(+), 0 deletions(-)

src/lib.zig+1
...@@ -223,5 +223,6 @@ pub fn countScalar(comptime T: type, haystack: []const T, needle: T) usize {...@@ -223,5 +223,6 @@ pub fn countScalar(comptime T: type, haystack: []const T, needle: T) usize {
223}223}
224224
225pub fn ptrCast(comptime T: type, ptr: *anyopaque) *T {225pub fn ptrCast(comptime T: type, ptr: *anyopaque) *T {
226 if (@alignOf(T) == 0) @compileError(@typeName(T));
226 return @ptrCast(*T, @alignCast(@alignOf(T), ptr));227 return @ptrCast(*T, @alignCast(@alignOf(T), ptr));
227}228}