| 1 |
// run |
| 2 |
|
| 3 |
// Copyright 2015 The Go Authors. All rights reserved. |
| 4 |
// Use of this source code is governed by a BSD-style |
| 5 |
// license that can be found in the LICENSE file. |
| 6 |
|
| 7 |
// Issue 10135: append a slice with zero-sized element used |
| 8 |
// to always return a slice with the same data pointer as the |
| 9 |
// old slice, even if it's nil, so this program used to panic |
| 10 |
// with nil pointer dereference because after append, s is a |
| 11 |
// slice with nil data pointer but non-zero len and cap. |
| 12 |
|
| 13 |
package main |
| 14 |
|
| 15 |
type empty struct{} |
| 16 |
|
| 17 |
func main() { |
| 18 |
var s []empty |
| 19 |
|
| 20 |
s = append(s, empty{}) |
| 21 |
|
| 22 |
for _, v := range s { |
| 23 |
_ = v |
| 24 |
} |
| 25 |
} |