Issue error if &=, |=, ^=, <<=, or >>= used with floats.

This commit is contained in:
Matt Pharr
2012-02-06 09:56:21 -08:00
parent 4e018d0a20
commit 2236d53def
3 changed files with 18 additions and 0 deletions

View File

@@ -2623,6 +2623,14 @@ AssignExpr::TypeCheck() {
if (rvalue == NULL)
return NULL;
if (lhsType->IsFloatType() == true &&
(op == ShlAssign || op == ShrAssign || op == AndAssign ||
op == XorAssign || op == OrAssign)) {
Error(pos, "Illegal to use %s operator with floating-point "
"operands.", lOpString(op));
return NULL;
}
// Make sure we're not assigning to a struct that has a constant member
const StructType *st = dynamic_cast<const StructType *>(lhsType);
if (st != NULL && lCheckForConstStructMember(pos, st, st))

View File

@@ -0,0 +1,5 @@
// First operand to binary operator "&" must be an integer or bool
float foo(float a, float b) {
return a & b;
}

View File

@@ -0,0 +1,5 @@
// Illegal to use ^= operator with floating-point
float foo(float a, float b) {
return a ^= b;
}