From: Robert Griesemer Date: Fri, 7 Mar 2014 01:11:13 +0000 (-0800) Subject: spec: clarify when constant slice indices must be in range X-Git-Tag: go1.3beta1~433 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=6ffd2351618b5c61a78ac9d78779868627dfd358;p=gostls13.git spec: clarify when constant slice indices must be in range This documents the status quo for most implementations, with one exception: gc generates a run-time error for constant but out-of-range indices when slicing a constant string. See issue 7200 for a detailed discussion. LGTM=r R=r, rsc, iant, ken CC=golang-codereviews https://golang.org/cl/72160044 --- diff --git a/doc/go_spec.html b/doc/go_spec.html index 0bf9d1da93..968db440f2 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1,6 +1,6 @@ @@ -2691,7 +2691,7 @@ For arrays or strings, the indices are in range if otherwise they are out of range. For slices, the upper index bound is the slice capacity cap(a) rather than the length. A constant index must be non-negative and representable by a value of type -int. +int; for arrays or constant strings, constant indices must also be in range. If both indices are constant, they must satisfy low <= high. If the indices are out of range at run time, a run-time panic occurs.

@@ -2751,7 +2751,7 @@ If the sliced operand is an array, it must be addre The indices are in range if 0 <= low <= high <= max <= cap(a), otherwise they are out of range. A constant index must be non-negative and representable by a value of type -int. +int; for arrays, constant indices must also be in range. If multiple indices are constant, the constants that are present must be in range relative to each other. If the indices are out of range at run time, a run-time panic occurs.