aboutsummaryrefslogtreecommitdiff
path: root/lib/std/heap.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2019-11-06 20:43:13 -0500
committerAndrew Kelley <andrew@ziglang.org>2019-11-06 20:44:15 -0500
commit6ee3cabe5cc0b2c9af30b1fa0233381faa18e700 (patch)
tree8070f9f0120559a410f07603b4b593f80ec68446 /lib/std/heap.zig
parent7277670843d259d19093c8900b1f8445e41202ae (diff)
downloadzig-6ee3cabe5cc0b2c9af30b1fa0233381faa18e700.tar.gz
zig-6ee3cabe5cc0b2c9af30b1fa0233381faa18e700.zip
allow type coercion from *[0]T to E![]const T
This is an unambiguous, safe cast.
Diffstat (limited to 'lib/std/heap.zig')
-rw-r--r--lib/std/heap.zig8
1 files changed, 3 insertions, 5 deletions
diff --git a/lib/std/heap.zig b/lib/std/heap.zig
index 8723c7eab6..ccdab8d332 100644
--- a/lib/std/heap.zig
+++ b/lib/std/heap.zig
@@ -41,8 +41,7 @@ var direct_allocator_state = Allocator{
const DirectAllocator = struct {
fn alloc(allocator: *Allocator, n: usize, alignment: u29) error{OutOfMemory}![]u8 {
- if (n == 0)
- return (([*]u8)(undefined))[0..0];
+ if (n == 0) return &[0]u8{};
if (builtin.os == .windows) {
const w = os.windows;
@@ -261,8 +260,7 @@ pub const HeapAllocator = switch (builtin.os) {
fn alloc(allocator: *Allocator, n: usize, alignment: u29) error{OutOfMemory}![]u8 {
const self = @fieldParentPtr(HeapAllocator, "allocator", allocator);
- if (n == 0)
- return (([*]u8)(undefined))[0..0];
+ if (n == 0) return &[0]u8{};
const amt = n + alignment + @sizeOf(usize);
const optional_heap_handle = @atomicLoad(?HeapHandle, &self.heap_handle, builtin.AtomicOrder.SeqCst);
@@ -677,7 +675,7 @@ pub fn StackFallbackAllocator(comptime size: usize) type {
) catch {
const result = try self.fallback_allocator.reallocFn(
self.fallback_allocator,
- ([*]u8)(undefined)[0..0],
+ &[0]u8{},
undefined,
new_size,
new_align,