From 8c058b32d1838e67d67277564b6cb9b0bccd1e75 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Tue, 18 Sep 2012 11:25:53 -0700 Subject: [PATCH] spec: clarify expression statements Function and method calls are valid expression statements, but calling certain built-in functions is not permitted. Enumerate the built-ins. Also: unsafe.Offsetof permits parenthesized selectors as arguments. This is simply documenting existing compiler behavior (both gc and gccgo agree). R=r, rsc, iant, ken CC=golang-dev https://golang.org/cl/6498138 --- doc/go_spec.html | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/doc/go_spec.html b/doc/go_spec.html index fc61bdd4c07..675970300dd 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1,6 +1,6 @@ @@ -3798,7 +3798,9 @@ Error: log.Panic("error encountered")

Expression statements

-Function calls, method calls, and receive operations +With the exception of specific built-in functions, +function and method calls and +receive operations can appear in statement context. Such statements may be parenthesized.

@@ -3806,11 +3808,21 @@ can appear in statement context. Such statements may be parenthesized. ExpressionStmt = Expression . +

+The following built-in functions are not permitted in statement context: +

+ +
+append cap complex imag len make new real
+unsafe.Alignof unsafe.Offsetof unsafe.Sizeof
+
+
 h(x+y)
 f.Close()
 <-ch
 (<-ch)
+len("foo")  // illegal if len is the built-in function
 
@@ -5492,8 +5504,8 @@ of any type and return the alignment or size, respectively, of a hypothetical va as if v was declared via var v = x.

-The function Offsetof takes a selector (ยงSelectors) denoting a struct -field of any type and returns the field offset in bytes relative to the +The function Offsetof takes a (possibly parenthesized) selector +denoting a struct field of any type and returns the field offset in bytes relative to the struct's address. For a struct s with field f: