linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Al Viro <viro@ftp.linux.org.uk>
To: linux-sparse@vger.kernel.org
Subject: Fix enumeration constants' scope beginning
Date: Mon, 09 Mar 2009 23:32:16 +0000	[thread overview]
Message-ID: <E1LgoxE-0005wC-Bf@ZenIV.linux.org.uk> (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.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
---
 parse.c                 |    7 +++----
 validation/enum_scope.c |   11 +++++++++++
 2 files changed, 14 insertions(+), 4 deletions(-)
 create mode 100644 validation/enum_scope.c

diff --git a/parse.c b/parse.c
index bffb690..c19822c 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]
+ */
-- 
1.5.6.5



                 reply	other threads:[~2009-03-09 23:32 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=E1LgoxE-0005wC-Bf@ZenIV.linux.org.uk \
    --to=viro@ftp.linux.org.uk \
    --cc=linux-sparse@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).