Commit 83feedf7 authored by Russ Cox's avatar Russ Cox

gc: fix error for floating-point constant %

R=ken2
CC=golang-dev
https://golang.org/cl/5674108
parent 03f2289f
......@@ -660,6 +660,14 @@ evconst(Node *n)
}
mpdivfltflt(v.u.fval, rv.u.fval);
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):
mpaddfltflt(&v.u.cval->real, &rv.u.cval->real);
mpaddfltflt(&v.u.cval->imag, &rv.u.cval->imag);
......
......@@ -16,11 +16,11 @@ const (
Int8 int8 = 101
Minus1 int8 = -1
Uint8 uint8 = 102
Const = 103
Const = 103
Float32 float32 = 104.5
Float64 float64 = 105.5
ConstFloat = 106.5
ConstFloat = 106.5
Big float64 = 1e300
String = "abc"
......@@ -38,32 +38,33 @@ var (
a8 = Int8 * Const / 100 // ERROR "overflow"
a9 = Int8 * (Const / 100) // OK
b1 = Uint8 * Uint8 // ERROR "overflow"
b2 = Uint8 * -1 // ERROR "overflow"
b3 = Uint8 - Uint8 // OK
b4 = Uint8 - Uint8 - Uint8 // ERROR "overflow"
b5 = uint8(^0) // ERROR "overflow"
b6 = ^uint8(0) // OK
b7 = uint8(Minus1) // ERROR "overflow"
b8 = uint8(int8(-1)) // ERROR "overflow"
b8a = uint8(-1) // ERROR "overflow"
b9 byte = (1 << 10) >> 8 // OK
b10 byte = (1 << 10) // ERROR "overflow"
b11 byte = (byte(1) << 10) >> 8 // ERROR "overflow"
b12 byte = 1000 // ERROR "overflow"
b13 byte = byte(1000) // ERROR "overflow"
b14 byte = byte(100) * byte(100) // ERROR "overflow"
b15 byte = byte(100) * 100 // ERROR "overflow"
b16 byte = byte(0) * 1000 // ERROR "overflow"
b16a byte = 0 * 1000 // OK
b17 byte = byte(0) * byte(1000) // ERROR "overflow"
b18 byte = Uint8 / 0 // ERROR "division by zero"
b1 = Uint8 * Uint8 // ERROR "overflow"
b2 = Uint8 * -1 // ERROR "overflow"
b3 = Uint8 - Uint8 // OK
b4 = Uint8 - Uint8 - Uint8 // ERROR "overflow"
b5 = uint8(^0) // ERROR "overflow"
b6 = ^uint8(0) // OK
b7 = uint8(Minus1) // ERROR "overflow"
b8 = uint8(int8(-1)) // ERROR "overflow"
b8a = uint8(-1) // ERROR "overflow"
b9 byte = (1 << 10) >> 8 // OK
b10 byte = (1 << 10) // ERROR "overflow"
b11 byte = (byte(1) << 10) >> 8 // ERROR "overflow"
b12 byte = 1000 // ERROR "overflow"
b13 byte = byte(1000) // ERROR "overflow"
b14 byte = byte(100) * byte(100) // ERROR "overflow"
b15 byte = byte(100) * 100 // ERROR "overflow"
b16 byte = byte(0) * 1000 // ERROR "overflow"
b16a byte = 0 * 1000 // OK
b17 byte = byte(0) * byte(1000) // ERROR "overflow"
b18 byte = Uint8 / 0 // ERROR "division by zero"
c1 float64 = Big
c2 float64 = Big * Big // ERROR "overflow"
c3 float64 = float64(Big) * Big // ERROR "overflow"
c4 = Big * Big // ERROR "overflow"
c5 = Big / 0 // ERROR "division by zero"
c1 float64 = Big
c2 float64 = Big * Big // ERROR "overflow"
c3 float64 = float64(Big) * Big // ERROR "overflow"
c4 = Big * Big // ERROR "overflow"
c5 = Big / 0 // ERROR "division by zero"
c6 = 1000 % 1e3 // ERROR "floating-point % operation"
)
func f(int)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment