Issue error if any complex assignment operator is used with a struct type.
Issue #275.
This commit is contained in:
12
expr.cpp
12
expr.cpp
@@ -2892,11 +2892,19 @@ AssignExpr::TypeCheck() {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure we're not assigning to a struct that has a constant member
|
|
||||||
const StructType *st = CastType<StructType>(lhsType);
|
const StructType *st = CastType<StructType>(lhsType);
|
||||||
if (st != NULL && lCheckForConstStructMember(pos, st, st))
|
if (st != NULL) {
|
||||||
|
// Make sure we're not assigning to a struct that has a constant member
|
||||||
|
if (lCheckForConstStructMember(pos, st, st))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
if (op != Assign) {
|
||||||
|
Error(lvalue->pos, "Assignment operator \"%s\" is illegal with struct "
|
||||||
|
"type \"%s\".", lOpString(op), st->GetString().c_str());
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
8
tests_errors/struct_arith.ispc
Normal file
8
tests_errors/struct_arith.ispc
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
// Assignment operator "+=" is illegal with struct type
|
||||||
|
|
||||||
|
struct Point { float x, y, z; };
|
||||||
|
|
||||||
|
void foo() {
|
||||||
|
Point a = {1,2,3}, b = {4,5,6};
|
||||||
|
a += b;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user