From patchwork Wed Dec 12 23:29:12 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: libgo patch committed: Delete from a nil map is now a no-op Date: Wed, 12 Dec 2012 13:29:12 -0000 From: Ian Taylor X-Patchwork-Id: 205687 Message-Id: To: gcc-patches@gcc.gnu.org, gofrontend-dev@googlegroups.com The Go spec was changed slightly: calling delete on a nil map is now a no-op, rather than causing a runtime panic. This patch implements that in gccgo. Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu. Committed to mainline. Ian Index: libgo/runtime/go-map-delete.c =================================================================== --- libgo/runtime/go-map-delete.c (revision 194274) +++ libgo/runtime/go-map-delete.c (working copy) @@ -27,7 +27,7 @@ __go_map_delete (struct __go_map *map, c void **pentry; if (map == NULL) - runtime_panicstring ("deletion of entry in nil map"); + return; descriptor = map->__descriptor; Index: gcc/testsuite/go.test/test/nil.go =================================================================== --- gcc/testsuite/go.test/test/nil.go (revision 193595) +++ gcc/testsuite/go.test/test/nil.go (working copy) @@ -151,9 +151,8 @@ func maptest() { shouldPanic(func() { m[2] = 3 }) - shouldPanic(func() { - delete(m, 2) - }) + // can delete (non-existent) entries + delete(m, 2) } // nil slice