diff --git a/expr.cpp b/expr.cpp index b1194603..7a36a4bb 100644 --- a/expr.cpp +++ b/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(lhsType); if (st != NULL && lCheckForConstStructMember(pos, st, st)) diff --git a/tests_errors/float-logical-1.ispc b/tests_errors/float-logical-1.ispc new file mode 100644 index 00000000..9aad44c5 --- /dev/null +++ b/tests_errors/float-logical-1.ispc @@ -0,0 +1,5 @@ +// First operand to binary operator "&" must be an integer or bool + +float foo(float a, float b) { + return a & b; +} diff --git a/tests_errors/float-logical.ispc b/tests_errors/float-logical.ispc new file mode 100644 index 00000000..27ab4c8c --- /dev/null +++ b/tests_errors/float-logical.ispc @@ -0,0 +1,5 @@ +// Illegal to use ^= operator with floating-point + +float foo(float a, float b) { + return a ^= b; +}