Issue error if &=, |=, ^=, <<=, or >>= used with floats.
This commit is contained in:
8
expr.cpp
8
expr.cpp
@@ -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))
|
||||
|
||||
5
tests_errors/float-logical-1.ispc
Normal file
5
tests_errors/float-logical-1.ispc
Normal 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;
|
||||
}
|
||||
5
tests_errors/float-logical.ispc
Normal file
5
tests_errors/float-logical.ispc
Normal file
@@ -0,0 +1,5 @@
|
||||
// Illegal to use ^= operator with floating-point
|
||||
|
||||
float foo(float a, float b) {
|
||||
return a ^= b;
|
||||
}
|
||||
Reference in New Issue
Block a user