Source file test/fixedbugs/issue4654.go

     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|is not used"
    16  	go string([]byte("abc")) // ERROR "go requires function call, not conversion|is not used"
    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|is not used"
    24  	defer cap(x) // ERROR "defer discards result of cap|is not used"
    25  	defer complex(1, 2) // ERROR "defer discards result of complex|is not used"
    26  	defer complex(f, 1) // ERROR "defer discards result of complex|is not used"
    27  	defer imag(1i) // ERROR "defer discards result of imag|is not used"
    28  	defer imag(c) // ERROR "defer discards result of imag|is not used"
    29  	defer len(x) // ERROR "defer discards result of len|is not used"
    30  	defer make([]int, 1) // ERROR "defer discards result of make|is not used"
    31  	defer make(chan bool) // ERROR "defer discards result of make|is not used"
    32  	defer make(map[string]int) // ERROR "defer discards result of make|is not used"
    33  	defer new(int) // ERROR "defer discards result of new|is not used"
    34  	defer real(1i) // ERROR "defer discards result of real|is not used"
    35  	defer real(c) // ERROR "defer discards result of real|is not used"
    36  	defer append(x, 1) // ERROR "defer discards result of append|is not used"
    37  	defer append(x, 1) // ERROR "defer discards result of append|is not used"
    38  	defer unsafe.Alignof(t.X) // ERROR "defer discards result of unsafe.Alignof|is not used"
    39  	defer unsafe.Offsetof(t.X) // ERROR "defer discards result of unsafe.Offsetof|is not used"
    40  	defer unsafe.Sizeof(t) // ERROR "defer discards result of unsafe.Sizeof|is not used"
    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|is not used"
    51  	string([]byte("abc")) // ERROR "string\(.*\) evaluated but not used|is 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  }
    72  

View as plain text