From e730a5364b21b3d8fed9afe8d7b87d7dc905abfa Mon Sep 17 00:00:00 2001 From: Matt Pharr Date: Fri, 8 Jun 2012 11:29:02 -0700 Subject: [PATCH] Issue error if any complex assignment operator is used with a struct type. Issue #275. --- expr.cpp | 14 +++++++++++--- tests_errors/struct_arith.ispc | 8 ++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 tests_errors/struct_arith.ispc diff --git a/expr.cpp b/expr.cpp index 7c270f46..cc03ba20 100644 --- a/expr.cpp +++ b/expr.cpp @@ -2892,10 +2892,18 @@ AssignExpr::TypeCheck() { return NULL; } - // Make sure we're not assigning to a struct that has a constant member const StructType *st = CastType(lhsType); - if (st != NULL && lCheckForConstStructMember(pos, st, st)) - return NULL; + if (st != 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; } diff --git a/tests_errors/struct_arith.ispc b/tests_errors/struct_arith.ispc new file mode 100644 index 00000000..9d942880 --- /dev/null +++ b/tests_errors/struct_arith.ispc @@ -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; +}