aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--parse.c7
-rw-r--r--validation/enum_scope.c11
2 files changed, 14 insertions, 4 deletions
diff --git a/parse.c b/parse.c
index 4b75637..9fb606a 100644
--- a/parse.c
+++ b/parse.c
@@ -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;
diff --git a/validation/enum_scope.c b/validation/enum_scope.c
new file mode 100644
index 0000000..92ffc8e
--- /dev/null
+++ b/validation/enum_scope.c
@@ -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]
+ */