ref: 7b66933103d3d4930735aec4dd0d739d0efe78e4
parent: c8abdfe1b720a9d786ea3fd840d48b744ef07e06
author: Roberto E. Vargas Caballero <[email protected]>
date: Fri Jul 11 07:50:03 EDT 2014
Allow variables with same name of typedef of external contexts It is legal a code like: typedef int pepe; main() { int pepe; } So, we have to detect when we already have a type in the declaration and don't generate an error when we get a TYPENAME in this case. It is also necessary add a new rule in directdcl in order to allow create a new symbol from the string of a TYPENAME.
--- a/cc1/decl.c
+++ b/cc1/decl.c
@@ -68,12 +68,13 @@
dp = declarator0(dp, flags);
expect(')');
} else if (flags) {
- if (yytoken != IDEN) {
- if (flags & ID_EXPECTED)
- unexpected();
- sym = install("", NS_IDEN);
- } else {
+ if (yytoken == IDEN ||
+ yytoken == TYPE && yylval.token == TYPENAME) {
sym = newiden();
+ } else if (flags & ID_EXPECTED) {
+ unexpected();
+ } else {
+ sym = install("", NS_IDEN);
}
dp->op = IDEN;
dp->u.sym = sym;
@@ -186,6 +187,8 @@
case STRUCT: case UNION:
dcl = structdcl; p = &type; break;
case TYPENAME:
+ if (type)
+ goto check_types;
tp = yylval.sym->type;
case VOID: case BOOL: case CHAR:
case INT: case FLOAT: case DOUBLE: