mirror of
https://github.com/mirror/tinycc.git
synced 2025-03-26 12:04:59 +08:00
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>
This commit is contained in:
parent
0f522fb32a
commit
82969f045c
9
tccgen.c
9
tccgen.c
@ -2738,7 +2738,7 @@ static void parse_attribute(AttributeDef *ad)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* enum/struct/union declaration. u is either VT_ENUM or VT_STRUCT */
|
/* 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 a, v, size, align, maxalign, c, offset;
|
||||||
int bit_size, bit_pos, bsize, bt, lbit_pos, prevbt;
|
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)
|
if (s->type.t != a)
|
||||||
tcc_error("invalid type");
|
tcc_error("invalid type");
|
||||||
goto do_decl;
|
goto do_decl;
|
||||||
}
|
} else if (tok >= TOK_IDENT && !tdef)
|
||||||
|
tcc_error("unknown struct/union/enum");
|
||||||
} else {
|
} else {
|
||||||
v = anon_sym++;
|
v = anon_sym++;
|
||||||
}
|
}
|
||||||
@ -3014,14 +3015,14 @@ static int parse_btype(CType *type, AttributeDef *ad)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case TOK_ENUM:
|
case TOK_ENUM:
|
||||||
struct_decl(&type1, VT_ENUM);
|
struct_decl(&type1, VT_ENUM, t & VT_TYPEDEF);
|
||||||
basic_type2:
|
basic_type2:
|
||||||
u = type1.t;
|
u = type1.t;
|
||||||
type->ref = type1.ref;
|
type->ref = type1.ref;
|
||||||
goto basic_type1;
|
goto basic_type1;
|
||||||
case TOK_STRUCT:
|
case TOK_STRUCT:
|
||||||
case TOK_UNION:
|
case TOK_UNION:
|
||||||
struct_decl(&type1, VT_STRUCT);
|
struct_decl(&type1, VT_STRUCT, t & VT_TYPEDEF);
|
||||||
goto basic_type2;
|
goto basic_type2;
|
||||||
|
|
||||||
/* type modifiers */
|
/* type modifiers */
|
||||||
|
Loading…
Reference in New Issue
Block a user