diff --git a/doc/go_spec.html b/doc/go_spec.html index b59b37fd552..e0602418e80 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1,6 +1,6 @@ @@ -6789,11 +6789,17 @@ and whose length and capacity are len: (*[len]ArbitraryType)(unsafe.Pointer(ptr))[:] +

+As a special case, if ptr is nil and len is zero, +Slice returns nil. +

+

The len argument must be of integer type or an untyped constant. A constant len argument must be non-negative and representable by a value of type int; if it is an untyped constant it is given type int. -If ptr is nil or len is negative at run time, +At run time, if len is negative, +or if ptr is nil and len is not zero, a run-time panic occurs.

diff --git a/src/unsafe/unsafe.go b/src/unsafe/unsafe.go index ecbd28c523e..eaf72c96181 100644 --- a/src/unsafe/unsafe.go +++ b/src/unsafe/unsafe.go @@ -221,8 +221,11 @@ func Add(ptr Pointer, len IntegerType) Pointer // // (*[len]ArbitraryType)(unsafe.Pointer(ptr))[:] // +// As a special case, if ptr is nil and len is zero, Slice returns nil. +// // The len argument must be of integer type or an untyped constant. // A constant len argument must be non-negative and representable by a value of type int; // if it is an untyped constant it is given type int. -// If ptr is nil or len is negative at run time, a run-time panic occurs. +// At run time, if len is negative, or if ptr is nil and len is not zero, +// a run-time panic occurs. func Slice(ptr *ArbitraryType, len IntegerType) []ArbitraryType