Issue error if any complex assignment operator is used with a struct type.

Issue #275.
This commit is contained in:
Matt Pharr
2012-06-08 11:29:02 -07:00
parent 92b3ae41dd
commit e730a5364b
2 changed files with 19 additions and 3 deletions

View File

@@ -2892,10 +2892,18 @@ 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) {
return NULL; // Make sure we're not assigning to a struct that has a constant member
if (lCheckForConstStructMember(pos, st, st))
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;
} }

View 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;
}