]> Cypherpunks.ru repositories - gostls13.git/blob - test/shift1.go
test: test cases for issue 1708.
[gostls13.git] / test / shift1.go
1 // errchk $G -e $D/$F.go
2
3 // Copyright 2011 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 1708, illegal cases.
8
9 package p
10
11 func f(x int) int         { return 0 }
12 func g(x interface{}) int { return 0 }
13 func h(x float64) int     { return 0 }
14
15 // from the spec
16 var (
17         s uint    = 33
18         u         = 1.0 << s // ERROR "invalid operation"
19         v float32 = 1 << s   // ERROR "invalid operation"
20 )
21
22 // non-constant shift expressions
23 var (
24         e1       = g(2.0 << s) // ERROR "invalid operation"
25         f1       = h(2 << s)   // ERROR "invalid operation"
26         g1 int64 = 1.1 << s    // ERROR "truncated"
27 )
28
29 // constant shift expressions
30 const c uint = 65
31
32 var (
33         a2 int = 1.0 << c    // ERROR "overflow"
34         b2     = 1.0 << c    // ERROR "overflow"
35         d2     = f(1.0 << c) // ERROR "overflow"
36 )