From 871698136d7a6452267b90e06d7cab4fc1f7cfea Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Mon, 3 Mar 2014 20:07:34 -0800 Subject: [PATCH] spec: clarify what is considered a function call for len/cap special case gccgo considers built-in function calls returning a constant not as function call (issue 7386) go/types considers any call (regular or built-in) as a function call The wording and examples clarify that only "function calls" that are issued at run-time (and thus do not result in a constant result) are considered function calls in this case. gc is inconsistent (issue 7385) gccgo already interprets the spec accordingly and issue 7386 is moot. go/types considers all calls (constant or not) as function calls (issue 7457). Fixes #7387. Fixes #7386. LGTM=r, rsc, iant R=r, rsc, iant, ken CC=golang-codereviews https://golang.org/cl/66860046 --- doc/go_spec.html | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/doc/go_spec.html b/doc/go_spec.html index 59b30739c6..9043431c4d 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1,6 +1,6 @@ @@ -5271,12 +5271,22 @@ The expression len(s) is constant if s is a string constant. The expressions len(s) and cap(s) are constants if the type of s is an array or pointer to an array and the expression s does not contain -channel receives or +channel receives or (non-constant) function calls; in this case s is not evaluated. Otherwise, invocations of len and cap are not constant and s is evaluated.

+
+const (
+	c1 = imag(2i)                    // imag(2i) = 2.0 is a constant
+	c2 = len([10]float64{2})         // [10]float64{2} contains no function calls
+	c3 = len([10]float64{c1})        // [10]float64{c1} contains no function calls
+	c4 = len([10]float64{imag(2i)})  // imag(2i) is a constant and no function call is issued
+	c5 = len([10]float64{imag(z)})   // invalid: imag(x) is a (non-constant) function call
+)
+var z complex128
+

Allocation

-- 2.48.1