Merge from mainline (167278:168000).
[official-gcc/graphite-test-results.git] / gcc / testsuite / go.test / test / const1.go
blob427d61e59c3b748a868cae67322348e3f7e8d9f5
1 // errchk $G -e $F.go
3 // Copyright 2009 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.
7 package main
9 type I interface {}
10 const (
11 // assume all types behave similarly to int8/uint8
12 Int8 int8 = 101
13 Minus1 int8 = -1
14 Uint8 uint8 = 102
15 Const = 103
17 Float32 float32 = 104.5
18 Float float = 105.5
19 ConstFloat = 106.5
20 Big float64 = 1e300
22 String = "abc"
23 Bool = true
26 var (
27 a1 = Int8 * 100 // ERROR "overflow"
28 a2 = Int8 * -1 // OK
29 a3 = Int8 * 1000 // ERROR "overflow"
30 a4 = Int8 * int8(1000) // ERROR "overflow"
31 a5 = int8(Int8 * 1000) // ERROR "overflow"
32 a6 = int8(Int8 * int8(1000)) // ERROR "overflow"
33 a7 = Int8 - 2*Int8 - 2*Int8 // ERROR "overflow"
34 a8 = Int8 * Const / 100 // ERROR "overflow"
35 a9 = Int8 * (Const / 100) // OK
37 b1 = Uint8 * Uint8 // ERROR "overflow"
38 b2 = Uint8 * -1 // ERROR "overflow"
39 b3 = Uint8 - Uint8 // OK
40 b4 = Uint8 - Uint8 - Uint8 // ERROR "overflow"
41 b5 = uint8(^0) // ERROR "overflow"
42 b6 = ^uint8(0) // OK
43 b7 = uint8(Minus1) // ERROR "overflow"
44 b8 = uint8(int8(-1)) // ERROR "overflow"
45 b8a = uint8(-1) // ERROR "overflow"
46 b9 byte = (1<<10) >> 8 // OK
47 b10 byte = (1<<10) // ERROR "overflow"
48 b11 byte = (byte(1)<<10) >> 8 // ERROR "overflow"
49 b12 byte = 1000 // ERROR "overflow"
50 b13 byte = byte(1000) // ERROR "overflow"
51 b14 byte = byte(100) * byte(100) // ERROR "overflow"
52 b15 byte = byte(100) * 100 // ERROR "overflow"
53 b16 byte = byte(0) * 1000 // ERROR "overflow"
54 b16a byte = 0 * 1000 // OK
55 b17 byte = byte(0) * byte(1000) // ERROR "overflow"
56 b18 byte = Uint8/0 // ERROR "division by zero"
58 c1 float64 = Big
59 c2 float64 = Big*Big // ERROR "overflow"
60 c3 float64 = float64(Big)*Big // ERROR "overflow"
61 c4 = Big*Big // ERROR "overflow"
62 c5 = Big/0 // ERROR "division by zero"
65 func f(int)
67 func main() {
68 f(Int8) // ERROR "convert|wrong type|cannot"
69 f(Minus1) // ERROR "convert|wrong type|cannot"
70 f(Uint8) // ERROR "convert|wrong type|cannot"
71 f(Const) // OK
72 f(Float32) // ERROR "convert|wrong type|cannot"
73 f(Float) // ERROR "convert|wrong type|cannot"
74 f(ConstFloat) // ERROR "truncate"
75 f(ConstFloat - 0.5) // OK
76 f(Big) // ERROR "convert|wrong type|cannot"
77 f(String) // ERROR "convert|wrong type|cannot|incompatible"
78 f(Bool) // ERROR "convert|wrong type|cannot|incompatible"