]> Cypherpunks.ru repositories - gostls13.git/commitdiff
cmd/gc: reject builtin function calls in len(fixed array) constants
authorRuss Cox <rsc@golang.org>
Thu, 3 Apr 2014 23:04:33 +0000 (19:04 -0400)
committerRuss Cox <rsc@golang.org>
Thu, 3 Apr 2014 23:04:33 +0000 (19:04 -0400)
Fixes #7385.

LGTM=iant
R=golang-codereviews, iant
CC=golang-codereviews
https://golang.org/cl/84010044

src/cmd/gc/const.c
test/const5.go

index cfd81e86f5987281e3b7ad6db13854267ec5924f..28d0725d33d948f991bd42b37eaf92b7ba738ddf 100644 (file)
@@ -1629,10 +1629,25 @@ hascallchan(Node *n)
        if(n == N)
                return 0;
        switch(n->op) {
+       case OAPPEND:
        case OCALL:
        case OCALLFUNC:
-       case OCALLMETH:
        case OCALLINTER:
+       case OCALLMETH:
+       case OCAP:
+       case OCLOSE:
+       case OCOMPLEX:
+       case OCOPY:
+       case ODELETE:
+       case OIMAG:
+       case OLEN:
+       case OMAKE:
+       case ONEW:
+       case OPANIC:
+       case OPRINT:
+       case OPRINTN:
+       case OREAL:
+       case ORECOVER:
        case ORECV:
                return 1;
        }
index 87fe33a385515317ea9f0e59314ec3c7870d4155..60b4d0d12c4f13ed95dda13a777335e807a626be 100644 (file)
@@ -18,6 +18,7 @@ var s [][30]int
 
 func f() *[40]int
 var c chan *[50]int
+var z complex128
 
 const (
        n1 = len(b.a)
@@ -29,5 +30,8 @@ const (
 
        n6 = cap(f())  // ERROR "is not a constant|is not constant"
        n7 = cap(<-c) // ERROR "is not a constant|is not constant"
+       n8 = real(z) // ERROR "is not a constant|is not constant"
+       n9 = len([4]float64{real(z)}) // ERROR "is not a constant|is not constant"
+
 )