Don't endlessly recurse on invalid nested typedefs

see testcase.
This commit is contained in:
Michael Matz 2019-04-07 03:15:05 +02:00
parent d00f98a7a5
commit 5ac2a26666
3 changed files with 11 additions and 1 deletions

View File

@ -2782,7 +2782,7 @@ ST_FUNC int type_size(CType *type, int *a)
*a = PTR_SIZE;
return PTR_SIZE;
}
} else if (IS_ENUM(type->t) && type->ref->c == -1) {
} else if (IS_ENUM(type->t) && type->ref->c < 0) {
return -1; /* incomplete enum */
} else if (bt == VT_LDOUBLE) {
*a = LDOUBLE_ALIGN;
@ -3934,6 +3934,7 @@ do_decl:
next();
if (s->c != -1)
tcc_error("struct/union/enum already defined");
s->c = -2;
/* cannot be empty */
/* non empty enums are not allowed */
ps = &s->next;

View File

@ -160,4 +160,10 @@ void foo(void) {
i = 42.2;
}
}
#elif defined test_nested_types
union u {
union u {
int i;
} m;
};
#endif

View File

@ -74,3 +74,6 @@
[test_conflicting_types]
60_errors_and_warnings.c:159: error: conflicting types for 'i'
[test_nested_types]
60_errors_and_warnings.c:166: error: struct/union/enum already defined