-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Open
Labels
bugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behavior
Description
Zig Version
0.15.1
Steps to Reproduce and Observed Behavior
Related to discussions about comptime allocators in #1291 and #25198. I was able to reproduce this with any pointer, which is why the repro has *const void
; it seems to have nothing to do with the fact that it was a function pointer like I thought in #25198.
or
const std = @import("std");
const Allocator = std.mem.Allocator;
const Alignment = std.mem.Alignment;
pub const comptime_allocator: Allocator = .{
.ptr = undefined,
.vtable = &.{
.alloc = &comptimeAlloc,
.resize = &comptimeResize,
.remap = &comptimeRemap,
.free = &Allocator.noFree,
},
};
fn comptimeAlloc(_: *anyopaque, len: usize, alignment: Alignment, ra: usize) ?[*]u8 {
_ = ra;
var buf: [len]u8 align(alignment.toByteUnits()) = undefined;
return &buf;
}
fn comptimeResize(_: *anyopaque, mem: []u8, alignment: Alignment, new_len: usize, ra: usize) bool {
_ = alignment;
_ = ra;
return new_len <= mem.len; // allow shrinking in-place
}
fn comptimeRemap(_: *anyopaque, mem: []u8, alignment: Alignment, new_len: usize, ra: usize) ?[*]u8 {
_ = alignment;
_ = ra;
return if (new_len <= mem.len) mem.ptr else null; // allow shrinking in-place
}
comptime {
var fns: std.ArrayList(*const void) = .empty;
fns.append(comptime_allocator, &{});
}
Expected Behavior
Either it compiles successfully or fails with a compiler error
Metadata
Metadata
Assignees
Labels
bugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behavior