diff options
author | Matthew Dempsky <mdempsky@google.com> | 2014-08-15 11:33:31 -0700 |
---|---|---|
committer | Matthew Dempsky <mdempsky@google.com> | 2014-08-15 11:33:31 -0700 |
commit | 1849dc0f1fe5915df8506c99b4f6f801defcc0ef (patch) | |
tree | 090d0c6668a5880fc80b800dafec10172c10f6d0 /test | |
parent | 3d78a68f79efd683346332202ae38c218b6c946e (diff) | |
download | go-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.go | 25 |
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" |