diff options
author | Al Viro <viro@ftp.linux.org.uk> | 2009-03-09 23:32:16 +0000 |
---|---|---|
committer | Christopher Li <sparse@chrisli.org> | 2009-07-18 05:30:09 +0000 |
commit | c14911db43a7229ba7a28ac23f4d1e569a2586ab (patch) | |
tree | cdc075ecc76deb111f4d767c74aea8e1b3c5b782 | |
parent | Restore __attribute__((mode)) handling (diff) | |
download | sparse-c14911db43a7229ba7a28ac23f4d1e569a2586ab.tar.gz sparse-c14911db43a7229ba7a28ac23f4d1e569a2586ab.tar.bz2 sparse-c14911db43a7229ba7a28ac23f4d1e569a2586ab.zip |
Fix enumeration constants' scope beginning
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.
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Christopher Li <sparse@chrisli.org>
-rw-r--r-- | parse.c | 7 | ||||
-rw-r--r-- | validation/enum_scope.c | 11 |
2 files changed, 14 insertions, 4 deletions
@@ -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] + */ |