OSDN Git Service

PR c/18946
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 27 Jan 2005 12:38:38 +0000 (12:38 +0000)
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 27 Jan 2005 12:38:38 +0000 (12:38 +0000)
* c-decl.c (warn_if_shadowing): Handle old_decl error_mark_node.
(pushdecl): Only use DECL_FILE_SCOPE_P if DECL_P.
(implicitly_declare): Handle error_mark_node.

* gcc.dg/noncompile/20050120-1.c: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@94320 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/c-decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/noncompile/20050120-1.c [new file with mode: 0644]

index 6999c43..51b5a55 100644 (file)
@@ -1,3 +1,10 @@
+2005-01-27  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c/18946
+       * c-decl.c (warn_if_shadowing): Handle old_decl error_mark_node.
+       (pushdecl): Only use DECL_FILE_SCOPE_P if DECL_P.
+       (implicitly_declare): Handle error_mark_node.
+
 2005-01-27  Richard Henderson  <rth@redhat.com>
 
        PR tree-opt/14329
index 61521e8..6e8c742 100644 (file)
@@ -1850,7 +1850,13 @@ warn_if_shadowing (tree new_decl)
       {
        tree old_decl = b->decl;
 
-       if (TREE_CODE (old_decl) == PARM_DECL)
+       if (old_decl == error_mark_node)
+         {
+           warning ("%Jdeclaration of %qD shadows previous non-variable",
+                    new_decl, new_decl);
+           break;
+         }
+       else if (TREE_CODE (old_decl) == PARM_DECL)
          warning ("%Jdeclaration of %qD shadows a parameter",
                   new_decl, new_decl);
        else if (DECL_FILE_SCOPE_P (old_decl))
@@ -1858,15 +1864,16 @@ warn_if_shadowing (tree new_decl)
                   new_decl, new_decl);
        else if (TREE_CODE (old_decl) == FUNCTION_DECL
                 && DECL_BUILT_IN (old_decl))
-         warning ("%Jdeclaration of %qD shadows a built-in function",
-                  new_decl, new_decl);
+         {
+           warning ("%Jdeclaration of %qD shadows a built-in function",
+                    new_decl, new_decl);
+           break;
+         }
        else
          warning ("%Jdeclaration of %qD shadows a previous local",
                   new_decl, new_decl);
 
-       if (TREE_CODE (old_decl) != FUNCTION_DECL
-           || !DECL_BUILT_IN (old_decl))
-         warning ("%Jshadowed declaration is here", old_decl);
+       warning ("%Jshadowed declaration is here", old_decl);
 
        break;
       }
@@ -2032,7 +2039,7 @@ pushdecl (tree x)
             its type saved; the others will already have had their
             proper types saved and the types will not have changed as
             their scopes will not have been re-entered.  */
-         if (DECL_FILE_SCOPE_P (b->decl) && !type_saved)
+         if (DECL_P (b->decl) && DECL_FILE_SCOPE_P (b->decl) && !type_saved)
            {
              b->type = TREE_TYPE (b->decl);
              type_saved = true;
@@ -2206,6 +2213,9 @@ implicitly_declare (tree functionid)
 
   if (decl)
     {
+      if (decl == error_mark_node)
+       return decl;
+
       /* FIXME: Objective-C has weird not-really-builtin functions
         which are supposed to be visible automatically.  They wind up
         in the external scope because they're pushed before the file
index deceb4a..fc2fb75 100644 (file)
@@ -1,3 +1,8 @@
+2005-01-27  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c/18946
+       * gcc.dg/noncompile/20050120-1.c: New test.
+
 2005-01-26  Diego Novillo  <dnovillo@redhat.com>
 
        PR tree-optimization/19633
diff --git a/gcc/testsuite/gcc.dg/noncompile/20050120-1.c b/gcc/testsuite/gcc.dg/noncompile/20050120-1.c
new file mode 100644 (file)
index 0000000..4af84b6
--- /dev/null
@@ -0,0 +1,19 @@
+/* PR c/18946 */
+/* { dg-do compile } */
+/* { dg-options "-Wshadow" } */
+
+void bar (void)
+{
+  {
+    if (foo)           /* { dg-error "undeclared|for each" } */
+      foo ();          /* { dg-warning "shadows previous" } */
+  }
+}
+
+void baz (void)
+{
+  if (foo)             /* { dg-error "undeclared" } */
+    {
+      int foo;         /* { dg-warning "shadows previous" } */
+    }
+}