modernc.org/gc@v1.0.1-0.20240304020402-f0dba7c97c2b/testdata/errchk/test/fixedbugs/issue4463.go (about)

     1  // errorcheck
     2  
     3  // Copyright 2012 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 4463: test builtin functions in statement context and in
     8  // go/defer functions.
     9  
    10  package p
    11  
    12  import "unsafe"
    13  
    14  func F() {
    15  	var a []int
    16  	var c chan int
    17  	var m map[int]int
    18  	var s struct{ f int }
    19  
    20  	append(a, 0)			// ERROR "not used"
    21  	cap(a)				// ERROR "not used"
    22  	complex(1, 2)			// ERROR "not used"
    23  	imag(1i)			// ERROR "not used"
    24  	len(a)				// ERROR "not used"
    25  	make([]int, 10)			// ERROR "not used"
    26  	new(int)			// ERROR "not used"
    27  	real(1i)			// ERROR "not used"
    28  	unsafe.Alignof(a)		// ERROR "not used"
    29  	unsafe.Offsetof(s.f)		// ERROR "not used"
    30  	unsafe.Sizeof(a)		// ERROR "not used"
    31  
    32  	close(c)
    33  	copy(a, a)
    34  	delete(m, 0)
    35  	panic(0)
    36  	print("foo")
    37  	println("bar")
    38  	recover()
    39  
    40  	(close(c))
    41  	(copy(a, a))
    42  	(delete(m, 0))
    43  	(panic(0))
    44  	(print("foo"))
    45  	(println("bar"))
    46  	(recover())
    47  
    48  	go append(a, 0)			// ERROR "not used|discards result"
    49  	go cap(a)			// ERROR "not used|discards result"
    50  	go complex(1, 2)		// ERROR "not used|discards result"
    51  	go imag(1i)			// ERROR "not used|discards result"
    52  	go len(a)			// ERROR "not used|discards result"
    53  	go make([]int, 10)		// ERROR "not used|discards result"
    54  	go new(int)			// ERROR "not used|discards result"
    55  	go real(1i)			// ERROR "not used|discards result"
    56  	go unsafe.Alignof(a)		// ERROR "not used|discards result"
    57  	go unsafe.Offsetof(s.f)		// ERROR "not used|discards result"
    58  	go unsafe.Sizeof(a)		// ERROR "not used|discards result"
    59  
    60  	go close(c)
    61  	go copy(a, a)
    62  	go delete(m, 0)
    63  	go panic(0)
    64  	go print("foo")
    65  	go println("bar")
    66  	go recover()
    67  
    68  	defer append(a, 0)		// ERROR "not used|discards result"
    69  	defer cap(a)			// ERROR "not used|discards result"
    70  	defer complex(1, 2)		// ERROR "not used|discards result"
    71  	defer imag(1i)			// ERROR "not used|discards result"
    72  	defer len(a)			// ERROR "not used|discards result"
    73  	defer make([]int, 10)		// ERROR "not used|discards result"
    74  	defer new(int)			// ERROR "not used|discards result"
    75  	defer real(1i)			// ERROR "not used|discards result"
    76  	defer unsafe.Alignof(a)		// ERROR "not used|discards result"
    77  	defer unsafe.Offsetof(s.f)	// ERROR "not used|discards result"
    78  	defer unsafe.Sizeof(a)		// ERROR "not used|discards result"
    79  
    80  	defer close(c)
    81  	defer copy(a, a)
    82  	defer delete(m, 0)
    83  	defer panic(0)
    84  	defer print("foo")
    85  	defer println("bar")
    86  	defer recover()
    87  }