diff options
author | Russ Cox <rsc@golang.org> | 2013-02-01 23:10:02 -0500 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2013-02-01 23:10:02 -0500 |
commit | 1688d2d3509547436f2e6900efee3b23d18773d8 (patch) | |
tree | 3ca83bae682c1177f1d4d9cae6370210cf354cef /test/const1.go | |
parent | d8d17d345bee871b8c550e4d51164b86fcd53a3d (diff) | |
download | go-1688d2d3509547436f2e6900efee3b23d18773d8.tar.gz |
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
Diffstat (limited to 'test/const1.go')
-rw-r--r-- | test/const1.go | 6 |
1 files changed, 6 insertions, 0 deletions
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" |