Skip to contentSkip to conversation

Fix enumeration constants' scope beginning

PATCH Al Viro 1 participant 1 message Mar 9, 2009 Sparse checker

lore
Share & tools
lore

Al Viro

author
#0 lore raw

It starts after the end of enumerator; i.e. if we have

enum {
	...
	Foo = expression,
	...
};

the scope of Foo starts only after the end of expression.
Rationale: 6.2.1p7.

---
 parse.c                 |    7 +++----
 validation/enum_scope.c |   11 +++++++++++
 2 files changed, 14 insertions(+), 4 deletions(-)
 create mode 100644 validation/enum_scope.c
parse.c +3 -4
index bffb690..c19822c 100644
@@ -804,10 +804,6 @@ static struct token *parse_enum_declaration(struct token *token, struct symbol *
 		struct token *next = token->next;
 		struct symbol *sym;
 
-		sym = alloc_symbol(token->pos, SYM_NODE);
-		bind_symbol(sym, token->ident, NS_SYMBOL);
-		sym->ctype.modifiers &= ~MOD_ADDRESSABLE;
-
 		if (match_op(next, '=')) {
 			next = constant_expression(next->next, &expr);
 			lastval = get_expression_value(expr);
@@ -828,6 +824,9 @@ static struct token *parse_enum_declaration(struct token *token, struct symbol *
 			expr->ctype = ctype;
 		}
 
+		sym = alloc_symbol(token->pos, SYM_NODE);
+		bind_symbol(sym, token->ident, NS_SYMBOL);
+		sym->ctype.modifiers &= ~MOD_ADDRESSABLE;
 		sym->initializer = expr;
 		sym->enum_member = 1;
 		sym->ctype.base_type = parent;
validation/enum_scope.c new file +11 -0
new file mode 100644
index 0000000..92ffc8e
@@ -0,0 +1,11 @@
+enum {A = 12};
+
+static void f(void)
+{
+	enum {A = A + 1, B};
+	char s[1 - 2 * (B != 14)];
+}
+
+/*
+ * check-name: enumeration constants' scope [6.2.1p7]
+ */
Signature · 1 line
1.5.6.5