aboutsummaryrefslogtreecommitdiff
path: root/expr.c
diff options
context:
space:
mode:
authorMichael Forney <mforney@mforney.org>2019-02-17 15:17:01 -0800
committerMichael Forney <mforney@mforney.org>2019-02-17 19:04:25 -0800
commit132e0c466c4198445f8e327c291ab38fe79f6032 (patch)
treeb9708ed3ca0f1f243054a9296031e7867a99b11f /expr.c
parent0beaca9548a524557d33d3c618e5ec586cf489d3 (diff)
Fix sizeof with unparenthesized postfix or compound literal expression
Determining whether it is a typename or unparenthesized expression requires consuming the '(', so we need to call postfixexpr/parseinit ourselves.
Diffstat (limited to 'expr.c')
-rw-r--r--expr.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/expr.c b/expr.c
index 4cc45b4..1c0f4ff 100644
--- a/expr.c
+++ b/expr.c
@@ -603,13 +603,20 @@ unaryexpr(struct scope *s)
next();
if (consume(TLPAREN)) {
t = typename(s);
- if (!t) {
+ if (t) {
+ expect(TRPAREN, "after type name");
+ /* might be part of a compound literal */
+ if (op == TSIZEOF && tok.kind == TLBRACE)
+ parseinit(s, t);
+ } else {
e = expr(s);
+ expect(TRPAREN, "after expression");
+ if (op == TSIZEOF)
+ e = postfixexpr(s, e);
if (e->flags & EXPRFLAG_DECAYED)
e = e->unary.base;
t = e->type;
}
- expect(TRPAREN, "after type name");
} else if (op == TSIZEOF) {
e = unaryexpr(s);
if (e->flags & EXPRFLAG_DECAYED)