aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Preud'homme <robotux@celest.fr>2013-09-20 21:16:53 +0200
committerThomas Preud'homme <robotux@celest.fr>2013-09-20 21:22:11 +0200
commit82969f045c99b4d1ef833de35117c17b326b46c0 (patch)
tree74f61dd0c77bbdad045ed13d2815350a97ce03d6
parent0f522fb32a635dafce30f3ce3ff2cb15bcec809e (diff)
downloadtinycc-82969f045c99b4d1ef833de35117c17b326b46c0.tar.gz
tinycc-82969f045c99b4d1ef833de35117c17b326b46c0.tar.bz2
Report error when using undefined enum
Prevent the following code from compiling: int main(void) { enum rgb c = 42; return c; } Reported-by: John Haque <j.eh@mchsi.com>
-rw-r--r--tccgen.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/tccgen.c b/tccgen.c
index 53a2b6b..77ff87c 100644
--- a/tccgen.c
+++ b/tccgen.c
@@ -2738,7 +2738,7 @@ static void parse_attribute(AttributeDef *ad)
}
/* enum/struct/union declaration. u is either VT_ENUM or VT_STRUCT */
-static void struct_decl(CType *type, int u)
+static void struct_decl(CType *type, int u, int tdef)
{
int a, v, size, align, maxalign, c, offset;
int bit_size, bit_pos, bsize, bt, lbit_pos, prevbt;
@@ -2759,7 +2759,8 @@ static void struct_decl(CType *type, int u)
if (s->type.t != a)
tcc_error("invalid type");
goto do_decl;
- }
+ } else if (tok >= TOK_IDENT && !tdef)
+ tcc_error("unknown struct/union/enum");
} else {
v = anon_sym++;
}
@@ -3014,14 +3015,14 @@ static int parse_btype(CType *type, AttributeDef *ad)
}
break;
case TOK_ENUM:
- struct_decl(&type1, VT_ENUM);
+ struct_decl(&type1, VT_ENUM, t & VT_TYPEDEF);
basic_type2:
u = type1.t;
type->ref = type1.ref;
goto basic_type1;
case TOK_STRUCT:
case TOK_UNION:
- struct_decl(&type1, VT_STRUCT);
+ struct_decl(&type1, VT_STRUCT, t & VT_TYPEDEF);
goto basic_type2;
/* type modifiers */