summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMatthew Dempsky <mdempsky@google.com>2014-08-15 11:33:31 -0700
committerMatthew Dempsky <mdempsky@google.com>2014-08-15 11:33:31 -0700
commit1849dc0f1fe5915df8506c99b4f6f801defcc0ef (patch)
tree090d0c6668a5880fc80b800dafec10172c10f6d0 /test
parent3d78a68f79efd683346332202ae38c218b6c946e (diff)
downloadgo-1849dc0f1fe5915df8506c99b4f6f801defcc0ef.tar.gz
cmd/gc: disallow pointer constants
Fixes issue 7760. LGTM=iant R=iant, remyoudompheng CC=golang-codereviews https://codereview.appspot.com/130720043 Committer: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'test')
-rw-r--r--test/fixedbugs/issue7760.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/test/fixedbugs/issue7760.go b/test/fixedbugs/issue7760.go
new file mode 100644
index 000000000..cccae4891
--- /dev/null
+++ b/test/fixedbugs/issue7760.go
@@ -0,0 +1,25 @@
+// errorcheck
+
+// Copyright 2014 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Verify that pointers can't be used as constants.
+
+package main
+
+import "unsafe"
+
+type myPointer unsafe.Pointer
+
+const _ = unsafe.Pointer(uintptr(1)) // ERROR "is not (a )?constant"
+const _ = myPointer(uintptr(1)) // ERROR "is not (a )?constant"
+
+const _ = (*int)(unsafe.Pointer(uintptr(1))) // ERROR "is not (a )?constant"
+const _ = (*int)(myPointer(uintptr(1))) // ERROR "is not (a )?constant"
+
+const _ = uintptr(unsafe.Pointer(uintptr(1))) // ERROR "is not (a )?constant"
+const _ = uintptr(myPointer(uintptr(1))) // ERROR "is not (a )?constant"
+
+const _ = []byte("") // ERROR "is not (a )?constant"
+const _ = []rune("") // ERROR "is not (a )?constant"