blob: 048d0cb9f397634791841763e9de764967342918 [file] [log] [blame]
Russ Cox0b477ef2012-02-16 23:48:57 -05001// errorcheck
Russ Cox8f194bf2009-03-12 19:04:38 -07002
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.
6
Rob Pikefc0dc042012-02-19 13:19:43 +11007// Verify that large integer constant expressions cause overflow.
8// Does not compile.
9
Russ Cox8f194bf2009-03-12 19:04:38 -070010package main
11
12const (
Rob Pike4f61fc92010-09-04 10:36:13 +100013 A int = 1
Ian Lance Taylorbd64e812009-03-16 21:48:07 -070014 B byte; // ERROR "type without expr|expected .=."
Russ Cox8f194bf2009-03-12 19:04:38 -070015)
Russ Cox337547d2012-02-11 00:50:56 -050016
17const LargeA = 1000000000000000000
18const LargeB = LargeA * LargeA * LargeA
Ian Lance Taylor6ed800c2012-09-28 08:30:30 -070019const LargeC = LargeB * LargeB * LargeB // GC_ERROR "constant multiplication overflow"
Rémy Oudompheng79db6ad2012-02-16 00:19:42 +010020
Ian Lance Taylor6ed800c2012-09-28 08:30:30 -070021const AlsoLargeA = LargeA << 400 << 400 >> 400 >> 400 // GC_ERROR "constant shift overflow"