1
0
mirror of https://github.com/golang/go synced 2024-11-22 00:44:39 -07:00

test: don't assign address of array to slice.

R=rsc
CC=golang-dev
https://golang.org/cl/2084042
This commit is contained in:
Ian Lance Taylor 2010-08-31 07:34:01 -07:00
parent 0f61f0140d
commit 5309fae1a3
9 changed files with 14 additions and 14 deletions

View File

@ -13,8 +13,8 @@ var d1 chan<- int = c
var d2 = (chan<- int)(c) var d2 = (chan<- int)(c)
var e *[4]int var e *[4]int
var f1 []int = e var f1 []int = e[0:]
var f2 = []int(e) var f2 = []int(e[0:])
var g = []int(nil) var g = []int(nil)

View File

@ -13,7 +13,7 @@ type T struct {
func main() { func main() {
var ta []*T; var ta []*T;
ta = new([1]*T); ta = new([1]*T)[0:];
ta[0] = nil; ta[0] = nil;
} }
/* /*

View File

@ -25,7 +25,7 @@ func main() {
as := new([2]string); as := new([2]string);
as[0] = "0"; as[0] = "0";
as[1] = "1"; as[1] = "1";
m["0"] = as; m["0"] = as[0:];
a := m["0"]; a := m["0"];
a[0] = "x"; a[0] = "x";

View File

@ -9,7 +9,7 @@ package main
func main() { func main() {
type Slice []byte; type Slice []byte;
a := [...]byte{ 0 }; a := [...]byte{ 0 };
b := Slice(&a); // This should be OK. b := Slice(a[0:]); // This should be OK.
c := Slice(a); // ERROR "invalid|illegal|cannot" c := Slice(a); // ERROR "invalid|illegal|cannot"
_, _ = b, c; _, _ = b, c;
} }

View File

@ -81,8 +81,8 @@ func testpfpf() {
// call ptr dynamic with ptr fixed from new // call ptr dynamic with ptr fixed from new
func testpdpf1() { func testpdpf1() {
a := new([40]int) a := new([40]int)
setpd(a) setpd(a[0:])
res(sumpd(a), 0, 40) res(sumpd(a[0:]), 0, 40)
b := (*a)[5:30] b := (*a)[5:30]
res(sumpd(b), 5, 30) res(sumpd(b), 5, 30)
@ -92,8 +92,8 @@ func testpdpf1() {
func testpdpf2() { func testpdpf2() {
var a [80]int var a [80]int
setpd(&a) setpd(a[0:])
res(sumpd(&a), 0, 80) res(sumpd(a[0:]), 0, 80)
} }
// generate bounds error with ptr dynamic // generate bounds error with ptr dynamic

View File

@ -16,12 +16,12 @@ var t int
func main() { func main() {
lb = 0 lb = 0
hb = 10 hb = 10
by = &bx by = bx[0:]
tstb() tstb()
lb = 0 lb = 0
hb = 10 hb = 10
fy = &fx fy = fx[0:]
tstf() tstf()
// width 1 (byte) // width 1 (byte)

View File

@ -33,5 +33,5 @@ func main() {
// usual len and cap, we require the *array -> slice // usual len and cap, we require the *array -> slice
// conversion to do the check. // conversion to do the check.
var p *[1<<30]byte = nil; var p *[1<<30]byte = nil;
f(p); // should crash f(p[0:]); // should crash
} }

View File

@ -29,6 +29,6 @@ func main() {
// usual len and cap, we require the *array -> slice // usual len and cap, we require the *array -> slice
// conversion to do the check. // conversion to do the check.
var p *[1<<30]byte = nil; var p *[1<<30]byte = nil;
var x []byte = p; // should crash var x []byte = p[0:]; // should crash
_ = x; _ = x;
} }

View File

@ -31,5 +31,5 @@ func main() {
// conversion to do the check. // conversion to do the check.
var x []byte; var x []byte;
var y = &x; var y = &x;
*y = q; // should crash (uses arraytoslice runtime routine) *y = q[0:]; // should crash (uses arraytoslice runtime routine)
} }