2012-02-16 21:48:57 -07:00
|
|
|
// errorcheck
|
2009-03-12 20:04:38 -06: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-18 19:19:43 -07:00
|
|
|
// Verify that large integer constant expressions cause overflow.
|
|
|
|
// Does not compile.
|
|
|
|
|
2009-03-12 20:04:38 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
const (
|
2010-09-03 18:36:13 -06:00
|
|
|
A int = 1
|
2009-03-16 22:48:07 -06:00
|
|
|
B byte; // ERROR "type without expr|expected .=."
|
2009-03-12 20:04:38 -06:00
|
|
|
)
|
2012-02-10 22:50:56 -07:00
|
|
|
|
|
|
|
const LargeA = 1000000000000000000
|
|
|
|
const LargeB = LargeA * LargeA * LargeA
|
2012-09-28 09:30:30 -06:00
|
|
|
const LargeC = LargeB * LargeB * LargeB // GC_ERROR "constant multiplication overflow"
|
2012-02-15 16:19:42 -07:00
|
|
|
|
2012-09-28 09:30:30 -06:00
|
|
|
const AlsoLargeA = LargeA << 400 << 400 >> 400 >> 400 // GC_ERROR "constant shift overflow"
|
2020-11-24 22:56:47 -07: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"
|