github.com/xushiwei/go@v0.0.0-20130601165731-2b9d83f45bc9/test/fixedbugs/issue4654.go (about)

     1  // errorcheck
     2  
     3  // Copyright 2013 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 4654.
     8  // Check error for conversion and 'not used' in defer/go.
     9  
    10  package p
    11  
    12  import "unsafe"
    13  
    14  func f() {
    15  	defer int(0) // ERROR "defer requires function call, not conversion"
    16  	go string([]byte("abc")) // ERROR "go requires function call, not conversion"
    17  	
    18  	var c complex128
    19  	var f float64
    20  	var t struct {X int}
    21  
    22  	var x []int
    23  	defer append(x, 1) // ERROR "defer discards result of append"
    24  	defer cap(x) // ERROR "defer discards result of cap"
    25  	defer complex(1, 2) // ERROR "defer discards result of complex"
    26  	defer complex(f, 1) // ERROR "defer discards result of complex"
    27  	defer imag(1i) // ERROR "defer discards result of imag"
    28  	defer imag(c) // ERROR "defer discards result of imag"
    29  	defer len(x) // ERROR "defer discards result of len"
    30  	defer make([]int, 1) // ERROR "defer discards result of make"
    31  	defer make(chan bool) // ERROR "defer discards result of make"
    32  	defer make(map[string]int) // ERROR "defer discards result of make"
    33  	defer new(int) // ERROR "defer discards result of new"
    34  	defer real(1i) // ERROR "defer discards result of real"
    35  	defer real(c) // ERROR "defer discards result of real"
    36  	defer append(x, 1) // ERROR "defer discards result of append"
    37  	defer append(x, 1) // ERROR "defer discards result of append"
    38  	defer unsafe.Alignof(t.X) // ERROR "defer discards result of unsafe.Alignof"
    39  	defer unsafe.Offsetof(t.X) // ERROR "defer discards result of unsafe.Offsetof"
    40  	defer unsafe.Sizeof(t) // ERROR "defer discards result of unsafe.Sizeof"
    41  	
    42  	defer copy(x, x) // ok
    43  	m := make(map[int]int)
    44  	defer delete(m, 1) // ok
    45  	defer panic(1) // ok
    46  	defer print(1) // ok
    47  	defer println(1) // ok
    48  	defer recover() // ok
    49  
    50  	int(0) // ERROR "int\(0\) evaluated but not used"
    51  	string([]byte("abc")) // ERROR "string\(.*\) evaluated but not used"
    52  
    53  	append(x, 1) // ERROR "not used"
    54  	cap(x) // ERROR "not used"
    55  	complex(1, 2) // ERROR "not used"
    56  	complex(f, 1) // ERROR "not used"
    57  	imag(1i) // ERROR "not used"
    58  	imag(c) // ERROR "not used"
    59  	len(x) // ERROR "not used"
    60  	make([]int, 1) // ERROR "not used"
    61  	make(chan bool) // ERROR "not used"
    62  	make(map[string]int) // ERROR "not used"
    63  	new(int) // ERROR "not used"
    64  	real(1i) // ERROR "not used"
    65  	real(c) // ERROR "not used"
    66  	append(x, 1) // ERROR "not used"
    67  	append(x, 1) // ERROR "not used"
    68  	unsafe.Alignof(t.X) // ERROR "not used"
    69  	unsafe.Offsetof(t.X) // ERROR "not used"
    70  	unsafe.Sizeof(t) // ERROR "not used"
    71  }