Source file test/fixedbugs/issue7760.go

     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|invalid constant type"
    16  const _ = myPointer(uintptr(1)) // ERROR "is not (a )?constant|invalid constant type"
    17  
    18  const _ = (*int)(unsafe.Pointer(uintptr(1))) // ERROR "is not (a )?constant|invalid constant type"
    19  const _ = (*int)(myPointer(uintptr(1))) // ERROR "is not (a )?constant|invalid constant type"
    20  
    21  const _ = uintptr(unsafe.Pointer(uintptr(1))) // ERROR "is not (a )?constant|expression is not constant"
    22  const _ = uintptr(myPointer(uintptr(1))) // ERROR "is not (a )?constant|expression is no constant"
    23  
    24  const _ = []byte("") // ERROR "is not (a )?constant|invalid constant type"
    25  const _ = []rune("") // ERROR "is not (a )?constant|invalid constant type"
    26  

View as plain text