From 6ffd2351618b5c61a78ac9d78779868627dfd358 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Thu, 6 Mar 2014 17:11:13 -0800 Subject: [PATCH] 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 --- doc/go_spec.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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. -- 2.48.1