ref: cae714c448ebdea4a6de048b012927b96be9b628
parent: c1768b2e370906fc8418bc26cd69d88529c8c96b
author: Roberto E. Vargas Caballero <[email protected]>
date: Mon Apr 14 06:38:09 EDT 2014
Check against assigns to const variables It is implementation defined what happens in that cases, and I choose report an error.
--- a/expr.c
+++ b/expr.c
@@ -511,9 +511,10 @@
static Node *
assign(void)
{
- register Node *np1 = ternary(), *np2;
+ register Node *np1, *np2;
char *err;
+ np1 = ternary();
for (;;) {
register char op;
@@ -535,6 +536,8 @@
np2 = assign();
if (!np1->b.lvalue)
goto nolvalue;
+ if (isconst(np1->type->op))
+ goto const_mod;
/* TODO: if it necessary a 0 comparision? */
if ((np2 = convert(np2, np1->type)) == NULL)
goto incompatibles;
@@ -543,6 +546,9 @@
return_np:
return np1;
+const_mod:
+ err = "const value modified";
+ goto error;
nolvalue:
err = "lvalue required as left operand of assignment";
goto error;
--- a/types.c
+++ b/types.c
@@ -144,7 +144,7 @@
case ARY: letter = 'V'; break;
case ENUM: letter = 'E'; break;
case STRUCT: letter = 'S'; break;
- default: abort();
+ default: letter = tp->letter;
}
bp = xmalloc(sizeof(*bp));
bp->next = *tbl;