diff options
author | Michael Forney <mforney@mforney.org> | 2019-04-15 21:57:48 -0700 |
---|---|---|
committer | Michael Forney <mforney@mforney.org> | 2019-04-15 23:08:33 -0700 |
commit | 966e1f7b5ae375380f2e4c2a52fdea82ca3c01dd (patch) | |
tree | c02f384ecc285b0c147033f7aa60c662c51deeab | |
parent | 1891c1c81b7ed607d75eaaa4fde6d20121941085 (diff) | |
download | cproc-966e1f7b5ae375380f2e4c2a52fdea82ca3c01dd.tar.xz |
expr: Check operand to '&' operator
-rw-r--r-- | expr.c | 8 |
1 files changed, 8 insertions, 0 deletions
@@ -81,6 +81,14 @@ mkunaryexpr(enum tokenkind op, struct expr *base) base->decayed = false; return base; } + /* + Allow struct and union types even if they are not lvalues, + since we take their address when compiling member access. + */ + if (!base->lvalue && base->type->kind != TYPEFUNC && base->type->kind != TYPESTRUCT && base->type->kind != TYPEUNION) + error(&tok.loc, "'&' operand is not an lvalue or function designator"); + if (base->kind == EXPRBITFIELD) + error(&tok.loc, "cannot take address of bit-field"); expr = mkexpr(EXPRUNARY, mkpointertype(base->type, base->qual)); expr->unary.op = op; expr->unary.base = base; |