aboutsummaryrefslogtreecommitdiff
path: root/expr.c
diff options
context:
space:
mode:
authorMichael Forney <mforney@mforney.org>2019-12-27 23:30:02 -0800
committerMichael Forney <mforney@mforney.org>2019-12-27 23:30:02 -0800
commitd889bc80be5a2389240a24b30873138a54991e10 (patch)
tree6f9fc3d24b8e5110dd04880376372c0ef4ee2aa1 /expr.c
parent8589d9d364c07227f717868b8bdb18919d8f7530 (diff)
expr: Disallow function/incomplete types and bit-fields in sizeof/_Alignof
Diffstat (limited to 'expr.c')
-rw-r--r--expr.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/expr.c b/expr.c
index 171c239..98f6246 100644
--- a/expr.c
+++ b/expr.c
@@ -842,18 +842,24 @@ unaryexpr(struct scope *s)
expect(TRPAREN, "after expression");
if (op == TSIZEOF)
e = postfixexpr(s, e);
- if (e->decayed)
- e = e->base;
- t = e->type;
}
} else if (op == TSIZEOF) {
+ t = NULL;
e = unaryexpr(s);
+ } else {
+ error(&tok.loc, "expected ')' after '_Alignof'");
+ }
+ if (!t) {
if (e->decayed)
e = e->base;
+ if (e->kind == EXPRBITFIELD)
+ error(&tok.loc, "%s operator applied to bitfield expression", tokstr[op]);
t = e->type;
- } else {
- error(&tok.loc, "expected ')' after '_Alignof'");
}
+ if (t->incomplete)
+ error(&tok.loc, "%s operator applied to incomplete type", tokstr[op]);
+ if (t->kind == TYPEFUNC)
+ error(&tok.loc, "%s operator applied to function type", tokstr[op]);
e = mkconstexpr(&typeulong, op == TSIZEOF ? t->size : t->align);
break;
default: