diff mbox series

[v3,12/16] struct-attr: prepare to handle attributes at the end of struct definitions (3)

Message ID 20201231101034.59978-13-luc.vanoostenryck@gmail.com (mailing list archive)
State Mainlined, archived
Headers show
Series support __packed struct | expand

Commit Message

Luc Van Oostenryck Dec. 31, 2020, 10:10 a.m. UTC
Type attributes for struct can be placed either just after the
keyword 'struct' or after the '}' ending its definition but this
later case is currently ignored.

Prepare the handling of this by having the 3 following cases in sequence:
1) a tag is present
2) no tag present but is followed by an opening brace
3) neither of these, so it's an error.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 parse.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)
diff mbox series

Patch

diff --git a/parse.c b/parse.c
index 663f2141dbf4..69bfc2e0fe57 100644
--- a/parse.c
+++ b/parse.c
@@ -750,20 +750,17 @@  static struct token *struct_union_enum_specifier(enum type type,
 
 		// Mark the structure as needing re-examination
 		sym->examined = 0;
-		goto end;
-	}
-
-	// private struct/union/enum type
-	if (!match_op(token, '{')) {
+	} else if (match_op(token, '{')) {
+		// private struct/union/enum type
+		sym = alloc_symbol(token->pos, type);
+		set_current_scope(sym);		// used by dissect
+		ctx->ctype.base_type = sym;
+	} else {
 		sparse_error(token->pos, "expected declaration");
 		ctx->ctype.base_type = &bad_ctype;
 		return token;
 	}
 
-	sym = alloc_symbol(token->pos, type);
-	set_current_scope(sym);		// used by dissect
-	ctx->ctype.base_type = sym;
-end:
 	token = parse(token->next, sym);
 	token = expect(token, '}', "at end of specifier");