Russ Cox | 0b477ef | 2012-02-16 23:48:57 -0500 | [diff] [blame] | 1 | // errorcheck |
Russ Cox | 8f194bf | 2009-03-12 19:04:38 -0700 | [diff] [blame] | 2 | |
| 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 Pike | fc0dc04 | 2012-02-19 13:19:43 +1100 | [diff] [blame] | 7 | // Verify that large integer constant expressions cause overflow. |
| 8 | // Does not compile. |
| 9 | |
Russ Cox | 8f194bf | 2009-03-12 19:04:38 -0700 | [diff] [blame] | 10 | package main |
| 11 | |
| 12 | const ( |
Rob Pike | 4f61fc9 | 2010-09-04 10:36:13 +1000 | [diff] [blame] | 13 | A int = 1 |
Ian Lance Taylor | bd64e81 | 2009-03-16 21:48:07 -0700 | [diff] [blame] | 14 | B byte; // ERROR "type without expr|expected .=." |
Russ Cox | 8f194bf | 2009-03-12 19:04:38 -0700 | [diff] [blame] | 15 | ) |
Russ Cox | 337547d | 2012-02-11 00:50:56 -0500 | [diff] [blame] | 16 | |
| 17 | const LargeA = 1000000000000000000 |
| 18 | const LargeB = LargeA * LargeA * LargeA |
Ian Lance Taylor | 6ed800c | 2012-09-28 08:30:30 -0700 | [diff] [blame] | 19 | const LargeC = LargeB * LargeB * LargeB // GC_ERROR "constant multiplication overflow" |
Rémy Oudompheng | 79db6ad | 2012-02-16 00:19:42 +0100 | [diff] [blame] | 20 | |
Ian Lance Taylor | 6ed800c | 2012-09-28 08:30:30 -0700 | [diff] [blame] | 21 | const AlsoLargeA = LargeA << 400 << 400 >> 400 >> 400 // GC_ERROR "constant shift overflow" |