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

     1  // errorcheck
     2  
     3  // Copyright 2014 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  // Verify that pointers can't be used as constants.
     8  
     9  package main
    10  
    11  import "unsafe"
    12  
    13  type myPointer unsafe.Pointer
    14  
    15  const _ = unsafe.Pointer(uintptr(1)) // ERROR "is not (a )?constant"
    16  const _ = myPointer(uintptr(1)) // ERROR "is not (a )?constant"
    17  
    18  const _ = (*int)(unsafe.Pointer(uintptr(1))) // ERROR "is not (a )?constant"
    19  const _ = (*int)(myPointer(uintptr(1))) // ERROR "is not (a )?constant"
    20  
    21  const _ = uintptr(unsafe.Pointer(uintptr(1))) // ERROR "is not (a )?constant"
    22  const _ = uintptr(myPointer(uintptr(1))) // ERROR "is not (a )?constant"
    23  
    24  const _ = []byte("") // ERROR "is not (a )?constant"
    25  const _ = []rune("") // ERROR "is not (a )?constant"