File tree 2 files changed +12
-3
lines changed
2 files changed +12
-3
lines changed Original file line number Diff line number Diff line change 1
1
<!--{
2
2
"Title": "The Go Programming Language Specification",
3
- "Subtitle": "Version of Jun 22 , 2021",
3
+ "Subtitle": "Version of Jun 28 , 2021",
4
4
"Path": "/ref/spec"
5
5
}-->
6
6
@@ -6789,11 +6789,17 @@ <h3 id="Package_unsafe">Package <code>unsafe</code></h3>
6789
6789
(*[len]ArbitraryType)(unsafe.Pointer(ptr))[:]
6790
6790
</ pre >
6791
6791
6792
+ < p >
6793
+ As a special case, if < code > ptr</ code > is < code > nil</ code > and < code > len</ code > is zero,
6794
+ < code > Slice</ code > returns < code > nil</ code > .
6795
+ </ p >
6796
+
6792
6797
< p >
6793
6798
The < code > len</ code > argument must be of integer type or an untyped < a href ="#Constants "> constant</ a > .
6794
6799
A constant < code > len</ code > argument must be non-negative and < a href ="#Representability "> representable</ a > by a value of type < code > int</ code > ;
6795
6800
if it is an untyped constant it is given type < code > int</ code > .
6796
- If < code > ptr</ code > is < code > nil</ code > or < code > len</ code > is negative at run time,
6801
+ At run time, if < code > len</ code > is negative,
6802
+ or if < code > ptr</ code > is < code > nil</ code > and < code > len</ code > is not zero,
6797
6803
a < a href ="#Run_time_panics "> run-time panic</ a > occurs.
6798
6804
</ p >
6799
6805
Original file line number Diff line number Diff line change @@ -221,8 +221,11 @@ func Add(ptr Pointer, len IntegerType) Pointer
221
221
//
222
222
// (*[len]ArbitraryType)(unsafe.Pointer(ptr))[:]
223
223
//
224
+ // As a special case, if ptr is nil and len is zero, Slice returns nil.
225
+ //
224
226
// The len argument must be of integer type or an untyped constant.
225
227
// A constant len argument must be non-negative and representable by a value of type int;
226
228
// if it is an untyped constant it is given type int.
227
- // If ptr is nil or len is negative at run time, a run-time panic occurs.
229
+ // At run time, if len is negative, or if ptr is nil and len is not zero,
230
+ // a run-time panic occurs.
228
231
func Slice (ptr * ArbitraryType , len IntegerType ) []ArbitraryType
You can’t perform that action at this time.
0 commit comments