blob: 00d753c57267357c0b01bdc68e32fedd9cf9a774 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
// run
// Copyright 2025 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
// Issue #45624 is the proposal to accept new(expr) in go1.26.
// Here we test its run-time behavior.
func main() {
{
p := new(123) // untyped constant expr
if *p != 123 {
panic("wrong value")
}
}
{
x := 42
p := new(x) // non-constant expr
if *p != x {
panic("wrong value")
}
}
{
x := [2]int{123, 456}
p := new(x) // composite value
if *p != x {
panic("wrong value")
}
}
{
var i int
v := new(i > 0) // untyped expression, see issue #75617
if *v != false {
panic("wrong value")
}
}
}
// Regression test for ICE in staticdata.GlobalLinksym from
// use of autotemp outside a function (go.dev/issue/77237).
var (
x = new(0)
y = x
)
|