[go: up one dir, main page]

blob: 6d32baeec501331d50ff03933b9e12c152e38e04 [file] [log] [blame]
Brad Fitzpatrick39ad2082018-06-12 16:16:38 +00001// run
2
3// Copyright 2018 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// Test that string([]byte(string)) makes a copy and doesn't reduce to
8// nothing. (Issue 25834)
9
10package main
11
12import (
13 "reflect"
14 "unsafe"
15)
16
17func main() {
18 var (
19 buf = make([]byte, 2<<10)
20 large = string(buf)
21 sub = large[10:12]
22 subcopy = string([]byte(sub))
23 subh = *(*reflect.StringHeader)(unsafe.Pointer(&sub))
24 subcopyh = *(*reflect.StringHeader)(unsafe.Pointer(&subcopy))
25 )
26 if subh.Data == subcopyh.Data {
27 panic("sub and subcopy have the same underlying array")
28 }
29}