From: Robert Griesemer
Date: Tue, 14 May 2019 17:22:04 +0000 (-0700)
Subject: spec: clarify that slice a expression shares underlying array with operand
X-Git-Tag: go1.13beta1~295
X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=1e3ffb0c902fc282469e7748ce066ee9ea7a6580;p=gostls13.git
spec: clarify that slice a expression shares underlying array with operand
The spec was not very precise as to what happens with respect to sharing
if a sliced operand is (a pointer to) an array. Added a small clarification
and a supporting example.
Fixes #31689.
Change-Id: Ic49351bec2033abd3f5428154ec3e9a7c2c9eaa5
Reviewed-on: https://go-review.googlesource.com/c/go/+/177139
Reviewed-by: Matthew Dempsky
Reviewed-by: Rob Pike
Reviewed-by: Keith Randall
---
diff --git a/doc/go_spec.html b/doc/go_spec.html
index dea3afe498..fb4341be1d 100644
--- a/doc/go_spec.html
+++ b/doc/go_spec.html
@@ -1,6 +1,6 @@
@@ -3262,6 +3262,14 @@ is a nil
slice. Otherwise, if the result is a slice, it shares its
array with the operand.
+
+var a [10]int
+s1 := a[3:7] // underlying array of s1 is array a; &s1[2] == &a[5]
+s2 := s1[1:4] // underlying array of s2 is underlying array of s1 which is array a; &s2[1] == &a[5]
+s2[1] = 42 // s2[1] == s1[2] == a[5] == 42; they all refer to the same underlying array element
+
+
+
Full slice expressions