This makes int char c; and struct {} int c; generate an error. Thanks Mobi Phil for reporting.
Unified · Split
| @@ -2988,19 +2988,25 @@ static void struct_decl(CType *type, int u, int tdef) · 2987 unmodified lines | ||
| 2988 | 2988 | } |
| 2989 | 2989 | } |
| 2990 | 2990 | |
| 2991 | +/* return 1 if basic type is a type size (short, long, long long) */ | |
| 2992 | +int is_btype_size (int bt) | |
| 2993 | +{ | |
| 2994 | + return bt == VT_SHORT || bt == VT_LONG || bt == VT_LLONG; | |
| 2995 | +} | |
| 2996 | + | |
| 2991 | 2997 | /* return 0 if no type declaration. otherwise, return the basic type |
| 2992 | 2998 | and skip it. |
| 2993 | 2999 | */ |
| 2994 | 3000 | static int parse_btype(CType *type, AttributeDef *ad) |
| 2995 | 3001 | { |
| 2996 | − int t, u, type_found, typespec_found, typedef_found; | |
| 3002 | + int t, u, bt_size, complete, type_found, typespec_found; | |
| 2997 | 3003 | Sym *s; |
| 2998 | 3004 | CType type1; |
| 2999 | 3005 | |
| 3000 | 3006 | memset(ad, 0, sizeof(AttributeDef)); |
| 3007 | + complete = 0; | |
| 3001 | 3008 | type_found = 0; |
| 3002 | 3009 | typespec_found = 0; |
| 3003 | − typedef_found = 0; | |
| 3004 | 3010 | t = 0; |
| 3005 | 3011 | while(1) { |
| 3006 | 3012 | switch(tok) { |
| @@ -3015,9 +3021,12 @@ static int parse_btype(CType *type, AttributeDef *ad) · 8 unmodified lines | ||
| 3015 | 3021 | basic_type: |
| 3016 | 3022 | next(); |
| 3017 | 3023 | basic_type1: |
| 3018 | − if ((t & VT_BTYPE) != 0) | |
| 3024 | + if (complete) | |
| 3019 | 3025 | tcc_error("too many basic types"); |
| 3020 | 3026 | t |= u; |
| 3027 | + bt_size = is_btype_size (u & VT_BTYPE); | |
| 3028 | + if (u == VT_INT || (!bt_size && !(t & VT_TYPEDEF))) | |
| 3029 | + complete = 1; | |
| 3021 | 3030 | typespec_found = 1; |
| 3022 | 3031 | break; |
| 3023 | 3032 | case TOK_VOID: |
| @@ -3027,9 +3036,8 @@ static int parse_btype(CType *type, AttributeDef *ad) · 3 unmodified lines | ||
| 3027 | 3036 | u = VT_SHORT; |
| 3028 | 3037 | goto basic_type; |
| 3029 | 3038 | case TOK_INT: |
| 3030 | − next(); | |
| 3031 | − typespec_found = 1; | |
| 3032 | − break; | |
| 3039 | + u = VT_INT; | |
| 3040 | + goto basic_type; | |
| 3033 | 3041 | case TOK_LONG: |
| 3034 | 3042 | next(); |
| 3035 | 3043 | if ((t & VT_BTYPE) == VT_DOUBLE) { |
| @@ -3149,12 +3157,11 @@ static int parse_btype(CType *type, AttributeDef *ad) · 113 unmodified lines | ||
| 3149 | 3157 | type1.t &= ~(VT_STORAGE&~VT_TYPEDEF); |
| 3150 | 3158 | goto basic_type2; |
| 3151 | 3159 | default: |
| 3152 | − if (typespec_found || typedef_found) | |
| 3160 | + if (typespec_found) | |
| 3153 | 3161 | goto the_end; |
| 3154 | 3162 | s = sym_find(tok); |
| 3155 | 3163 | if (!s || !(s->type.t & VT_TYPEDEF)) |
| 3156 | 3164 | goto the_end; |
| 3157 | − typedef_found = 1; | |
| 3158 | 3165 | t |= (s->type.t & ~VT_TYPEDEF); |
| 3159 | 3166 | type->ref = s->type.ref; |
| 3160 | 3167 | if (s->r) { |