ref: 080e69990174ad65f1611d8169a6b1f0f03414ea
parent: 285d54fa5709638cd975b5fcfc6a54bed54b9abc
author: Roberto E. Vargas Caballero <[email protected]>
date: Fri Aug 14 14:13:50 EDT 2015
Fix cast() Cast() is a problematic function because we need see two tokens of the input, but the second token can be a typename, so we can not use ahead() because it only can return the next character of the input. The solution is to duplicate the rules. When cast() sees a '(' it means that can be a cast, or can be a parentheses expression, so it accepts the '(' and calls expr(), but due to the lost of recursivity the actions of postfix were not applied, so the solution is to call a modified version of postfix() before returning.
--- a/cc1/expr.c
+++ b/cc1/expr.c
@@ -779,11 +779,12 @@
}
static Node *
-postfix(void)
+postfix(Node *lp)
{
- Node *lp, *rp;
+ Node *rp;
- lp = primary();
+ if (!lp)
+ lp = primary();
for (;;) {
switch (yytoken) {
case '[':
@@ -869,7 +870,7 @@
case '~': op = OCPL; fun = integeruop; break;
case '&': op = OADDR; fun = address; break;
case '*': op = OPTR; fun = content; break;
- default: return postfix();
+ default: return postfix(NULL);
}
next();
@@ -906,6 +907,7 @@
default:
rp = expr();
expect(')');
+ rp = postfix(rp);
break;
}