github.com/alash3al/go@v0.0.0-20150827002835-d497eeb00540/src/cmd/vet/testdata/shift.go (about)

     1  // Copyright 2014 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // This file contains tests for the suspicious shift checker.
     6  
     7  package testdata
     8  
     9  func ShiftTest() {
    10  	var i8 int8
    11  	_ = i8 << 7
    12  	_ = (i8 + 1) << 8 // ERROR "\(i8 \+ 1\) too small for shift of 8"
    13  	_ = i8 << (7 + 1) // ERROR "i8 too small for shift of 8"
    14  	_ = i8 >> 8       // ERROR "i8 too small for shift of 8"
    15  	i8 <<= 8          // ERROR "i8 too small for shift of 8"
    16  	i8 >>= 8          // ERROR "i8 too small for shift of 8"
    17  	var i16 int16
    18  	_ = i16 << 15
    19  	_ = i16 << 16 // ERROR "i16 too small for shift of 16"
    20  	_ = i16 >> 16 // ERROR "i16 too small for shift of 16"
    21  	i16 <<= 16    // ERROR "i16 too small for shift of 16"
    22  	i16 >>= 16    // ERROR "i16 too small for shift of 16"
    23  	var i32 int32
    24  	_ = i32 << 31
    25  	_ = i32 << 32 // ERROR "i32 too small for shift of 32"
    26  	_ = i32 >> 32 // ERROR "i32 too small for shift of 32"
    27  	i32 <<= 32    // ERROR "i32 too small for shift of 32"
    28  	i32 >>= 32    // ERROR "i32 too small for shift of 32"
    29  	var i64 int64
    30  	_ = i64 << 63
    31  	_ = i64 << 64 // ERROR "i64 too small for shift of 64"
    32  	_ = i64 >> 64 // ERROR "i64 too small for shift of 64"
    33  	i64 <<= 64    // ERROR "i64 too small for shift of 64"
    34  	i64 >>= 64    // ERROR "i64 too small for shift of 64"
    35  	var u8 uint8
    36  	_ = u8 << 7
    37  	_ = u8 << 8 // ERROR "u8 too small for shift of 8"
    38  	_ = u8 >> 8 // ERROR "u8 too small for shift of 8"
    39  	u8 <<= 8    // ERROR "u8 too small for shift of 8"
    40  	u8 >>= 8    // ERROR "u8 too small for shift of 8"
    41  	var u16 uint16
    42  	_ = u16 << 15
    43  	_ = u16 << 16 // ERROR "u16 too small for shift of 16"
    44  	_ = u16 >> 16 // ERROR "u16 too small for shift of 16"
    45  	u16 <<= 16    // ERROR "u16 too small for shift of 16"
    46  	u16 >>= 16    // ERROR "u16 too small for shift of 16"
    47  	var u32 uint32
    48  	_ = u32 << 31
    49  	_ = u32 << 32 // ERROR "u32 too small for shift of 32"
    50  	_ = u32 >> 32 // ERROR "u32 too small for shift of 32"
    51  	u32 <<= 32    // ERROR "u32 too small for shift of 32"
    52  	u32 >>= 32    // ERROR "u32 too small for shift of 32"
    53  	var u64 uint64
    54  	_ = u64 << 63
    55  	_ = u64 << 64  // ERROR "u64 too small for shift of 64"
    56  	_ = u64 >> 64  // ERROR "u64 too small for shift of 64"
    57  	u64 <<= 64     // ERROR "u64 too small for shift of 64"
    58  	u64 >>= 64     // ERROR "u64 too small for shift of 64"
    59  	_ = u64 << u64 // Non-constant shifts should succeed.
    60  	var i int
    61  	_ = i << 31
    62  	_ = i << 32 // ERROR "i might be too small for shift of 32"
    63  	_ = i >> 32 // ERROR "i might be too small for shift of 32"
    64  	i <<= 32    // ERROR "i might be too small for shift of 32"
    65  	i >>= 32    // ERROR "i might be too small for shift of 32"
    66  	var u uint
    67  	_ = u << 31
    68  	_ = u << 32 // ERROR "u might be too small for shift of 32"
    69  	_ = u >> 32 // ERROR "u might be too small for shift of 32"
    70  	u <<= 32    // ERROR "u might be too small for shift of 32"
    71  	u >>= 32    // ERROR "u might be too small for shift of 32"
    72  	var p uintptr
    73  	_ = p << 31
    74  	_ = p << 32 // ERROR "p might be too small for shift of 32"
    75  	_ = p >> 32 // ERROR "p might be too small for shift of 32"
    76  	p <<= 32    // ERROR "p might be too small for shift of 32"
    77  	p >>= 32    // ERROR "p might be too small for shift of 32"
    78  }