1
0
mirror of https://github.com/golang/go synced 2024-11-21 22:24:40 -07:00

gc: fix error for floating-point constant %

R=ken2
CC=golang-dev
https://golang.org/cl/5674108
This commit is contained in:
Russ Cox 2012-02-19 00:12:31 -05:00
parent 03f2289f7e
commit 83feedf7bf
2 changed files with 36 additions and 27 deletions

View File

@ -660,6 +660,14 @@ evconst(Node *n)
} }
mpdivfltflt(v.u.fval, rv.u.fval); mpdivfltflt(v.u.fval, rv.u.fval);
break; break;
case TUP(OMOD, CTFLT):
// The default case above would print 'ideal % ideal',
// which is not quite an ideal error.
if(!n->diag) {
yyerror("illegal constant expression: floating-point %% operation");
n->diag = 1;
}
return;
case TUP(OADD, CTCPLX): case TUP(OADD, CTCPLX):
mpaddfltflt(&v.u.cval->real, &rv.u.cval->real); mpaddfltflt(&v.u.cval->real, &rv.u.cval->real);
mpaddfltflt(&v.u.cval->imag, &rv.u.cval->imag); mpaddfltflt(&v.u.cval->imag, &rv.u.cval->imag);

View File

@ -16,11 +16,11 @@ const (
Int8 int8 = 101 Int8 int8 = 101
Minus1 int8 = -1 Minus1 int8 = -1
Uint8 uint8 = 102 Uint8 uint8 = 102
Const = 103 Const = 103
Float32 float32 = 104.5 Float32 float32 = 104.5
Float64 float64 = 105.5 Float64 float64 = 105.5
ConstFloat = 106.5 ConstFloat = 106.5
Big float64 = 1e300 Big float64 = 1e300
String = "abc" String = "abc"
@ -38,32 +38,33 @@ var (
a8 = Int8 * Const / 100 // ERROR "overflow" a8 = Int8 * Const / 100 // ERROR "overflow"
a9 = Int8 * (Const / 100) // OK a9 = Int8 * (Const / 100) // OK
b1 = Uint8 * Uint8 // ERROR "overflow" b1 = Uint8 * Uint8 // ERROR "overflow"
b2 = Uint8 * -1 // ERROR "overflow" b2 = Uint8 * -1 // ERROR "overflow"
b3 = Uint8 - Uint8 // OK b3 = Uint8 - Uint8 // OK
b4 = Uint8 - Uint8 - Uint8 // ERROR "overflow" b4 = Uint8 - Uint8 - Uint8 // ERROR "overflow"
b5 = uint8(^0) // ERROR "overflow" b5 = uint8(^0) // ERROR "overflow"
b6 = ^uint8(0) // OK b6 = ^uint8(0) // OK
b7 = uint8(Minus1) // ERROR "overflow" b7 = uint8(Minus1) // ERROR "overflow"
b8 = uint8(int8(-1)) // ERROR "overflow" b8 = uint8(int8(-1)) // ERROR "overflow"
b8a = uint8(-1) // ERROR "overflow" b8a = uint8(-1) // ERROR "overflow"
b9 byte = (1 << 10) >> 8 // OK b9 byte = (1 << 10) >> 8 // OK
b10 byte = (1 << 10) // ERROR "overflow" b10 byte = (1 << 10) // ERROR "overflow"
b11 byte = (byte(1) << 10) >> 8 // ERROR "overflow" b11 byte = (byte(1) << 10) >> 8 // ERROR "overflow"
b12 byte = 1000 // ERROR "overflow" b12 byte = 1000 // ERROR "overflow"
b13 byte = byte(1000) // ERROR "overflow" b13 byte = byte(1000) // ERROR "overflow"
b14 byte = byte(100) * byte(100) // ERROR "overflow" b14 byte = byte(100) * byte(100) // ERROR "overflow"
b15 byte = byte(100) * 100 // ERROR "overflow" b15 byte = byte(100) * 100 // ERROR "overflow"
b16 byte = byte(0) * 1000 // ERROR "overflow" b16 byte = byte(0) * 1000 // ERROR "overflow"
b16a byte = 0 * 1000 // OK b16a byte = 0 * 1000 // OK
b17 byte = byte(0) * byte(1000) // ERROR "overflow" b17 byte = byte(0) * byte(1000) // ERROR "overflow"
b18 byte = Uint8 / 0 // ERROR "division by zero" b18 byte = Uint8 / 0 // ERROR "division by zero"
c1 float64 = Big c1 float64 = Big
c2 float64 = Big * Big // ERROR "overflow" c2 float64 = Big * Big // ERROR "overflow"
c3 float64 = float64(Big) * Big // ERROR "overflow" c3 float64 = float64(Big) * Big // ERROR "overflow"
c4 = Big * Big // ERROR "overflow" c4 = Big * Big // ERROR "overflow"
c5 = Big / 0 // ERROR "division by zero" c5 = Big / 0 // ERROR "division by zero"
c6 = 1000 % 1e3 // ERROR "floating-point % operation"
) )
func f(int) func f(int)