From 581edd643fb18a66c472f77e2f8cd3f4cea524a2 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 29 Jan 2019 21:47:26 -0500 Subject: backport copy elision changes This commit contains everything from the copy-elision-2 branch that does not have to do with copy elision directly, but is generally useful for master branch. * All const values know their parents, when applicable, not just structs and unions. * Null pointers in const values are represented explicitly, rather than as a HardCodedAddr value of 0. * Rename "maybe" to "optional" in various code locations. * Separate DeclVarSrc and DeclVarGen * Separate PtrCastSrc and PtrCastGen * Separate CmpxchgSrc and CmpxchgGen * Represent optional error set as an integer, using the 0 value. In a const value, it uses nullptr. * Introduce type_has_one_possible_value and use it where applicable. * Fix debug builds not setting memory to 0xaa when storing undefined. * Separate the type of a variable from the const value of a variable. * Use copy_const_val where appropriate. * Rearrange structs to pack data more efficiently. * Move test/cases/* to test/behavior/* * Use `std.debug.assertOrPanic` in behavior tests instead of `std.debug.assert`. * Fix outdated slice syntax in docs. --- test/cases/pointers.zig | 44 -------------------------------------------- 1 file changed, 44 deletions(-) delete mode 100644 test/cases/pointers.zig (limited to 'test/cases/pointers.zig') diff --git a/test/cases/pointers.zig b/test/cases/pointers.zig deleted file mode 100644 index 47afb60a2e..0000000000 --- a/test/cases/pointers.zig +++ /dev/null @@ -1,44 +0,0 @@ -const std = @import("std"); -const assert = std.debug.assert; - -test "dereference pointer" { - comptime testDerefPtr(); - testDerefPtr(); -} - -fn testDerefPtr() void { - var x: i32 = 1234; - var y = &x; - y.* += 1; - assert(x == 1235); -} - -test "pointer arithmetic" { - var ptr = c"abcd"; - - assert(ptr[0] == 'a'); - ptr += 1; - assert(ptr[0] == 'b'); - ptr += 1; - assert(ptr[0] == 'c'); - ptr += 1; - assert(ptr[0] == 'd'); - ptr += 1; - assert(ptr[0] == 0); - ptr -= 1; - assert(ptr[0] == 'd'); - ptr -= 1; - assert(ptr[0] == 'c'); - ptr -= 1; - assert(ptr[0] == 'b'); - ptr -= 1; - assert(ptr[0] == 'a'); -} - -test "double pointer parsing" { - comptime assert(PtrOf(PtrOf(i32)) == **i32); -} - -fn PtrOf(comptime T: type) type { - return *T; -} -- cgit v1.2.3