mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
spec: change unsafe.Slice((*T)(nil), 0) to return []T(nil)
Updates #46742. Change-Id: I044933a657cd1a5cdb29863e49751df5fe9c258a Reviewed-on: https://go-review.googlesource.com/c/go/+/331069 Run-TryBot: Matthew Dempsky <mdempsky@google.com> Trust: Matthew Dempsky <mdempsky@google.com> Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
parent
5385e2386b
commit
1519271a93
2 changed files with 12 additions and 3 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
<!--{
|
<!--{
|
||||||
"Title": "The Go Programming Language Specification",
|
"Title": "The Go Programming Language Specification",
|
||||||
"Subtitle": "Version of Jun 22, 2021",
|
"Subtitle": "Version of Jun 28, 2021",
|
||||||
"Path": "/ref/spec"
|
"Path": "/ref/spec"
|
||||||
}-->
|
}-->
|
||||||
|
|
||||||
|
|
@ -6789,11 +6789,17 @@ and whose length and capacity are <code>len</code>:
|
||||||
(*[len]ArbitraryType)(unsafe.Pointer(ptr))[:]
|
(*[len]ArbitraryType)(unsafe.Pointer(ptr))[:]
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
As a special case, if <code>ptr</code> is <code>nil</code> and <code>len</code> is zero,
|
||||||
|
<code>Slice</code> returns <code>nil</code>.
|
||||||
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
The <code>len</code> argument must be of integer type or an untyped <a href="#Constants">constant</a>.
|
The <code>len</code> argument must be of integer type or an untyped <a href="#Constants">constant</a>.
|
||||||
A constant <code>len</code> argument must be non-negative and <a href="#Representability">representable</a> by a value of type <code>int</code>;
|
A constant <code>len</code> argument must be non-negative and <a href="#Representability">representable</a> by a value of type <code>int</code>;
|
||||||
if it is an untyped constant it is given type <code>int</code>.
|
if it is an untyped constant it is given type <code>int</code>.
|
||||||
If <code>ptr</code> is <code>nil</code> or <code>len</code> is negative at run time,
|
At run time, if <code>len</code> is negative,
|
||||||
|
or if <code>ptr</code> is <code>nil</code> and <code>len</code> is not zero,
|
||||||
a <a href="#Run_time_panics">run-time panic</a> occurs.
|
a <a href="#Run_time_panics">run-time panic</a> occurs.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -221,8 +221,11 @@ func Add(ptr Pointer, len IntegerType) Pointer
|
||||||
//
|
//
|
||||||
// (*[len]ArbitraryType)(unsafe.Pointer(ptr))[:]
|
// (*[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.
|
// 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;
|
// 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 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
|
func Slice(ptr *ArbitraryType, len IntegerType) []ArbitraryType
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue