1 // errorcheck -0 -l -d=defer
4 // Copyright 2019 The Go Authors. All rights reserved.
5 // Use of this source code is governed by a BSD-style
6 // license that can be found in the LICENSE file.
8 // check that open-coded defers are used in expected situations
10 // TODO(jsing): Re-enable on riscv64 once open-coded defers are turned
11 // back on - see golang.org/issue/36786
21 for i := 0; i < 10; i++ {
24 defer func() { // ERROR "open-coded defer"
31 defer func() { // ERROR "heap-allocated defer"
38 defer func() { // ERROR "stack-allocated defer"
44 defer func() { // ERROR "stack-allocated defer"
48 defer func() { // ERROR "heap-allocated defer"
58 defer func() { // ERROR "open-coded defer"
62 fmt.Println("goto loop")
70 fmt.Println("goto loop")
71 defer func() { // ERROR "heap-allocated defer"
81 fmt.Println("goto loop")
85 // The current analysis doesn't end a backward goto loop, so this defer is
86 // considered to be inside a loop
87 defer func() { // ERROR "heap-allocated defer"