diff options
author | Michael Forney <mforney@mforney.org> | 2019-04-20 11:18:46 -0700 |
---|---|---|
committer | Michael Forney <mforney@mforney.org> | 2019-04-23 15:40:11 -0700 |
commit | 28f37f3a2278aba1652638c7642377ad442e54d7 (patch) | |
tree | 762a9233c2c4968d807e446035ac1f5d1bdcf396 | |
parent | 00d412a140c0d9d5bd08d61032a9f15385eceac7 (diff) |
expr: Add some type checking for unary operators
-rw-r--r-- | expr.c | 6 |
1 files changed, 6 insertions, 0 deletions
@@ -674,17 +674,23 @@ unaryexpr(struct scope *s) case TADD: next(); e = castexpr(s); + if (!(e->type->prop & PROPARITH)) + error(&tok.loc, "operand of unary '+' operator must have arithmetic type"); e = exprconvert(e, typeintpromote(e->type)); break; case TSUB: next(); e = castexpr(s); + if (!(e->type->prop & PROPARITH)) + error(&tok.loc, "operand of unary '-' operator must have arithmetic type"); e = exprconvert(e, typeintpromote(e->type)); e = mkbinaryexpr(&tok.loc, TSUB, mkconstexpr(&typeint, 0), e); break; case TBNOT: next(); e = castexpr(s); + if (!(e->type->prop & PROPINT)) + error(&tok.loc, "operand of '~' operator must have integer type"); e = exprconvert(e, typeintpromote(e->type)); e = mkbinaryexpr(&tok.loc, TXOR, e, mkconstexpr(e->type, -1)); break; |