c-decl.c (grokdeclarator): Reject extern redeclarations of static variables.
authorMark Mitchell <mark@codesourcery.com>
Tue, 15 Apr 2003 01:37:03 +0000 (01:37 +0000)
committerMark Mitchell <mmitchel@gcc.gnu.org>
Tue, 15 Apr 2003 01:37:03 +0000 (01:37 +0000)
* c-decl.c (grokdeclarator): Reject extern redeclarations of
static variables.

* gcc.c-torture/execute/scope-2.c: Move to ...
* gcc.dg/noncompile/scope.c: .... here.

From-SVN: r65615

gcc/ChangeLog
gcc/c-decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/scope-2.c [deleted file]
gcc/testsuite/gcc.dg/noncompile/scope.c [new file with mode: 0644]

index 1b40e3afd18dad6582994a3fe6ca6ada867bd3de..0aa770c92db20fe050533e623e0c103a08e9ddf8 100644 (file)
@@ -1,3 +1,8 @@
+2003-04-14  Mark Mitchell  <mark@codesourcery.com>
+
+       * c-decl.c (grokdeclarator): Reject extern redeclarations of
+       static variables.
+
 2003-04-14  Janis Johnson  <janis287@us.ibm.com>
 
        * config/rs6000/rs6000.md (define_constants): Define constants for
index be6ff79059d539fb799877205c5cfc82d389dcc7..50b7219b39355838565dea7141c213583582d862 100644 (file)
@@ -4375,7 +4375,22 @@ grokdeclarator (declarator, declspecs, decl_context, initialized)
          }
        else if (type_quals)
          type = c_build_qualified_type (type, type_quals);
-         
+
+       /* It is invalid to create an `extern' declaration for a
+          variable if there is a global declaration that is
+          `static'.  */
+       if (extern_ref && current_binding_level != global_binding_level)
+         {
+           tree global_decl;
+
+           global_decl = identifier_global_value (declarator);
+           if (global_decl 
+               && TREE_CODE (global_decl) == VAR_DECL
+               && !TREE_PUBLIC (global_decl))
+             error ("variable previously declared `static' redeclared "
+                    "`extern'");
+         }
+
        decl = build_decl (VAR_DECL, declarator, type);
        if (size_varies)
          C_DECL_VARIABLE_SIZE (decl) = 1;
index 1fc22eecce18fcccf37f584e0b279f0aad19be10..ab306f13bec2af9c1e3f959d4e2ea88a1f2b2959 100644 (file)
@@ -1,3 +1,8 @@
+2003-04-14  Mark Mitchell  <mark@codesourcery.com>
+
+       * gcc.c-torture/execute/scope-2.c: Move to ...
+       * gcc.dg/noncompile/scope.c: .... here.
+
 2003-04-14  Roger Sayle  <roger@eyesopen.com>
 
        * gcc.dg/20030414-2.c: New test case.
diff --git a/gcc/testsuite/gcc.c-torture/execute/scope-2.c b/gcc/testsuite/gcc.c-torture/execute/scope-2.c
deleted file mode 100644 (file)
index c9a4775..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-static int v = 3;
-
-f ()
-{
-  int v = 4;
-  {
-    extern int v;
-    if (v != 3)
-      abort ();
-  }
-}
-
-main ()
-{
-  f ();
-  exit (0);
-}
diff --git a/gcc/testsuite/gcc.dg/noncompile/scope.c b/gcc/testsuite/gcc.dg/noncompile/scope.c
new file mode 100644 (file)
index 0000000..0bfc3f2
--- /dev/null
@@ -0,0 +1,17 @@
+static int v = 3;
+
+f ()
+{
+  int v = 4;
+  {
+    extern int v; /* { dg-error "static" } */  
+    if (v != 3)
+      abort ();
+  }
+}
+
+main ()
+{
+  f ();
+  exit (0);
+}