From 1688d2d3509547436f2e6900efee3b23d18773d8 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Fri, 1 Feb 2013 23:10:02 -0500 Subject: cmd/gc: reject non-Go constants Expressions involving nil, even if they can be evaluated at compile time, do not count as Go constants and cannot be used in const initializers. Fixes issue 4673. Fixes issue 4680. R=ken2 CC=golang-dev https://codereview.appspot.com/7278043 --- test/const1.go | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'test/const1.go') diff --git a/test/const1.go b/test/const1.go index 1580b76c6..a170ce9e7 100644 --- a/test/const1.go +++ b/test/const1.go @@ -9,6 +9,8 @@ package main +import "unsafe" + type I interface{} const ( @@ -86,3 +88,7 @@ func main() { } const ptr = nil // ERROR "const.*nil" +const _ = string([]byte(nil)) // ERROR "is not a constant" +const _ = uintptr(unsafe.Pointer((*int)(nil))) // ERROR "is not a constant" +const _ = unsafe.Pointer((*int)(nil)) // ERROR "cannot be nil" +const _ = (*int)(nil) // ERROR "cannot be nil" -- cgit v1.2.1