Be not too unhappy (i.e. assert) if there is a typedef in a compound declaration.
authorChristoph Mallon <christoph.mallon@gmx.de>
Thu, 11 Dec 2008 21:22:07 +0000 (21:22 +0000)
committerChristoph Mallon <christoph.mallon@gmx.de>
Thu, 11 Dec 2008 21:22:07 +0000 (21:22 +0000)
[r24549]

parser.c

index 4409e92..c946b90 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -6520,50 +6520,55 @@ static void parse_compound_declarators(compound_t *compound,
                } else {
                        entity = parse_declarator(specifiers,
                                        DECL_MAY_BE_ABSTRACT | DECL_CREATE_COMPOUND_MEMBER);
-                       assert(entity->kind == ENTITY_COMPOUND_MEMBER);
+                       if (entity->kind == ENTITY_TYPEDEF) {
+                               errorf(&entity->base.source_position,
+                                               "typedef not allowed as compound member");
+                       } else {
+                               assert(entity->kind == ENTITY_COMPOUND_MEMBER);
 
-                       /* make sure we don't define a symbol multiple times */
-                       symbol_t *symbol = entity->base.symbol;
-                       if (symbol != NULL) {
-                               entity_t *prev = find_compound_entry(compound, symbol);
-                               if (prev != NULL) {
-                                       errorf(&entity->base.source_position,
-                                                       "multiple declarations of symbol '%Y' (declared %P)",
-                                                       symbol, &prev->base.source_position);
+                               /* make sure we don't define a symbol multiple times */
+                               symbol_t *symbol = entity->base.symbol;
+                               if (symbol != NULL) {
+                                       entity_t *prev = find_compound_entry(compound, symbol);
+                                       if (prev != NULL) {
+                                               errorf(&entity->base.source_position,
+                                                               "multiple declarations of symbol '%Y' (declared %P)",
+                                                               symbol, &prev->base.source_position);
+                                       }
                                }
-                       }
 
-                       if (token.type == ':') {
-                               source_position_t source_position = *HERE;
-                               next_token();
-                               expression_t *size = parse_constant_expression();
+                               if (token.type == ':') {
+                                       source_position_t source_position = *HERE;
+                                       next_token();
+                                       expression_t *size = parse_constant_expression();
 
-                               type_t *type          = entity->declaration.type;
-                               type_t *bitfield_type = make_bitfield_type(type, size,
-                                               &source_position, entity->base.symbol);
-                               entity->declaration.type = bitfield_type;
-                       } else {
-                               type_t *orig_type = entity->declaration.type;
-                               type_t *type      = skip_typeref(orig_type);
-                               if (is_type_function(type)) {
-                                       errorf(&entity->base.source_position,
-                                                       "compound member '%Y' must not have function type '%T'",
-                                                       entity->base.symbol, orig_type);
-                               } else if (is_type_incomplete(type)) {
-                                       /* §6.7.2.1:16 flexible array member */
-                                       if (is_type_array(type) &&
-                                                       token.type == ';'   &&
-                                                       look_ahead(1)->type == '}') {
-                                               compound->has_flexible_member = true;
-                                       } else {
+                                       type_t *type          = entity->declaration.type;
+                                       type_t *bitfield_type = make_bitfield_type(type, size,
+                                                       &source_position, entity->base.symbol);
+                                       entity->declaration.type = bitfield_type;
+                               } else {
+                                       type_t *orig_type = entity->declaration.type;
+                                       type_t *type      = skip_typeref(orig_type);
+                                       if (is_type_function(type)) {
                                                errorf(&entity->base.source_position,
-                                                               "compound member '%Y' has incomplete type '%T'",
+                                                               "compound member '%Y' must not have function type '%T'",
                                                                entity->base.symbol, orig_type);
+                                       } else if (is_type_incomplete(type)) {
+                                               /* §6.7.2.1:16 flexible array member */
+                                               if (is_type_array(type) &&
+                                                               token.type == ';'   &&
+                                                               look_ahead(1)->type == '}') {
+                                                       compound->has_flexible_member = true;
+                                               } else {
+                                                       errorf(&entity->base.source_position,
+                                                                       "compound member '%Y' has incomplete type '%T'",
+                                                                       entity->base.symbol, orig_type);
+                                               }
                                        }
                                }
-                       }
 
-                       append_entity(&compound->members, entity);
+                               append_entity(&compound->members, entity);
+                       }
                }
 
                if (token.type != ',')