2012-02-16 23:48:57 -05:00
|
|
|
// errorcheck
|
2009-03-12 19:04:38 -07:00
|
|
|
|
|
|
|
// Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2012-02-19 13:19:43 +11:00
|
|
|
// Verify that large integer constant expressions cause overflow.
|
|
|
|
// Does not compile.
|
|
|
|
|
2009-03-12 19:04:38 -07:00
|
|
|
package main
|
|
|
|
|
|
|
|
const (
|
2010-09-04 10:36:13 +10:00
|
|
|
A int = 1
|
2009-03-16 21:48:07 -07:00
|
|
|
B byte; // ERROR "type without expr|expected .=."
|
2009-03-12 19:04:38 -07:00
|
|
|
)
|
2012-02-11 00:50:56 -05:00
|
|
|
|
|
|
|
const LargeA = 1000000000000000000
|
|
|
|
const LargeB = LargeA * LargeA * LargeA
|
2012-09-28 08:30:30 -07:00
|
|
|
const LargeC = LargeB * LargeB * LargeB // GC_ERROR "constant multiplication overflow"
|
2012-02-16 00:19:42 +01:00
|
|
|
|
2012-09-28 08:30:30 -07:00
|
|
|
const AlsoLargeA = LargeA << 400 << 400 >> 400 >> 400 // GC_ERROR "constant shift overflow"
|
2020-11-24 21:56:47 -08:00
|
|
|
|
|
|
|
// Issue #42732.
|
|
|
|
|
|
|
|
const a = 1e+500000000
|
|
|
|
const b = a * a // ERROR "constant multiplication overflow"
|
|
|
|
const c = b * b
|
|
|
|
|
|
|
|
const MaxInt512 = (1<<256 - 1) * (1<<256 + 1)
|
|
|
|
const _ = MaxInt512 + 1 // ERROR "constant addition overflow"
|
|
|
|
const _ = MaxInt512 ^ -1 // ERROR "constant bitwise XOR overflow"
|
|
|
|
const _ = ^MaxInt512 // ERROR "constant bitwise complement overflow"
|