]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR objc/69844 (Possibly bogus error: unknown type name in ObjC code)
authorJakub Jelinek <jakub@redhat.com>
Tue, 23 Feb 2016 19:47:24 +0000 (20:47 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 23 Feb 2016 19:47:24 +0000 (20:47 +0100)
PR objc/69844
* c-parser.c (c_parser_for_statement): Properly handle ObjC classes
in id_kind reclassification.

* objc.dg/pr69844.m: New test.

From-SVN: r233643

gcc/c/ChangeLog
gcc/c/c-parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/objc.dg/pr69844.m [new file with mode: 0644]

index ae00338ec27ab446d46277a2bb6bdb4723059aa6..d0fbaba96ba09f644c7672739279949437bd24ad 100644 (file)
@@ -1,3 +1,9 @@
+2016-02-23  Jakub Jelinek  <jakub@redhat.com>
+
+       PR objc/69844
+       * c-parser.c (c_parser_for_statement): Properly handle ObjC classes
+       in id_kind reclassification.
+
 2016-02-16  Jakub Jelinek  <jakub@redhat.com>
 
        PR c/69835
index 23853be205fc045adbb50019ffb7f35f31121340..82c1d61b76afb3cdb3d9667fe987b43d6e0250d1 100644 (file)
@@ -5886,13 +5886,30 @@ c_parser_for_statement (c_parser *parser, bool ivdep)
   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 || VAR_P (decl))
-       /* If DECL is null, we don't know what this token might be.  Treat
-          it as an ID for better diagnostics; we'll error later on.  */
-       token->id_kind = C_ID_ID;
-      else if (TREE_CODE (decl) == TYPE_DECL)
-       token->id_kind = C_ID_TYPENAME;
+
+      if (token->id_kind != C_ID_CLASSNAME)
+       {
+         tree decl = lookup_name (token->value);
+
+         token->id_kind = C_ID_ID;
+         if (decl)
+           {
+             if (TREE_CODE (decl) == TYPE_DECL)
+               token->id_kind = C_ID_TYPENAME;
+           }
+         else if (c_dialect_objc ())
+           {
+             tree objc_interface_decl = objc_is_class_name (token->value);
+             /* Objective-C class names are in the same namespace as
+                variables and typedefs, and hence are shadowed by local
+                declarations.  */
+             if (objc_interface_decl)
+               {
+                 token->value = objc_interface_decl;
+                 token->id_kind = C_ID_CLASSNAME;
+               }
+           }
+       }
     }
 
   token_indent_info next_tinfo
index 4b8cb0193a0e42023d4fbfe9a93a099e36d078ed..8a9e3a02f886673b1450db57c28f0f13973ae53a 100644 (file)
@@ -1,3 +1,8 @@
+2016-02-23  Jakub Jelinek  <jakub@redhat.com>
+
+       PR objc/69844
+       * objc.dg/pr69844.m: New test.
+
 2016-02-23  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
 
        PR libgfortran/69456
diff --git a/gcc/testsuite/objc.dg/pr69844.m b/gcc/testsuite/objc.dg/pr69844.m
new file mode 100644 (file)
index 0000000..9abcc7a
--- /dev/null
@@ -0,0 +1,24 @@
+/* PR objc/69844 */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu99" } */
+
+@class D;
+
+void
+foo (void)
+{
+  for (;;)
+    ;
+  D *d = (id) 0;
+  (void) d;
+}
+
+void
+bar (void)
+{
+  for (int D = 0; D < 30; D++)
+    if (1)
+      ;
+  D *d = (id) 0;
+  (void) d;
+}