aboutsummaryrefslogtreecommitdiff
path: root/gcc/c
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2015-11-12 21:07:04 +0000
committerMarek Polacek <mpolacek@gcc.gnu.org>2015-11-12 21:07:04 +0000
commit9be4f715f4db43da3585dfbfaa4545e5b1e07dc1 (patch)
treed50942375e98f825bc9225724db1d802d970c51b /gcc/c
parent3f9bdfc332ffa04eeb42af53d371eed9410f1320 (diff)
downloadgcc-9be4f715f4db43da3585dfbfaa4545e5b1e07dc1.zip
gcc-9be4f715f4db43da3585dfbfaa4545e5b1e07dc1.tar.gz
gcc-9be4f715f4db43da3585dfbfaa4545e5b1e07dc1.tar.bz2
re PR c/67784 (Incorrect parsing when using declarations in for loops and typedefs)
PR c/67784 * c-parser.c (c_parser_for_statement): Reclassify the token in a correct scope. * gcc.dg/pr67784-1.c: New test. * gcc.dg/pr67784-2.c: New test. From-SVN: r230273
Diffstat (limited to 'gcc/c')
-rw-r--r--gcc/c/ChangeLog6
-rw-r--r--gcc/c/c-parser.c15
2 files changed, 21 insertions, 0 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog
index 87f6a2d..0191b45 100644
--- a/gcc/c/ChangeLog
+++ b/gcc/c/ChangeLog
@@ -1,3 +1,9 @@
+2015-11-12 Marek Polacek <polacek@redhat.com>
+
+ PR c/67784
+ * c-parser.c (c_parser_for_statement): Reclassify the token in
+ a correct scope.
+
2015-11-11 Marek Polacek <polacek@redhat.com>
PR c/68107
diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
index 2484b92..8949825 100644
--- a/gcc/c/c-parser.c
+++ b/gcc/c/c-parser.c
@@ -5749,6 +5749,21 @@ c_parser_for_statement (c_parser *parser, bool ivdep)
c_finish_loop (loc, cond, incr, body, c_break_label, c_cont_label, true);
add_stmt (c_end_compound_stmt (loc, block, flag_isoc99 || c_dialect_objc ()));
+ /* We might need to reclassify any previously-lexed identifier, e.g.
+ when we've left a for loop with an if-statement without else in the
+ body - we might have used a wrong scope for the token. See PR67784. */
+ if (c_parser_next_token_is (parser, CPP_NAME))
+ {
+ c_token *token = c_parser_peek_token (parser);
+ tree decl = lookup_name (token->value);
+ if (decl == NULL_TREE)
+ ;
+ else if (TREE_CODE (decl) == TYPE_DECL)
+ token->id_kind = C_ID_TYPENAME;
+ else if (VAR_P (decl))
+ token->id_kind = C_ID_ID;
+ }
+
token_indent_info next_tinfo
= get_token_indent_info (c_parser_peek_token (parser));
warn_for_misleading_indentation (for_tinfo, body_tinfo, next_tinfo);