re PR c/15360 (c99: extern w/initializer; extern w/internal linkage)
authorJoseph Myers <jsm@polyomino.org.uk>
Sun, 25 Jul 2004 18:42:24 +0000 (19:42 +0100)
committerJoseph Myers <jsm28@gcc.gnu.org>
Sun, 25 Jul 2004 18:42:24 +0000 (19:42 +0100)
PR c/15360
* c-decl.c (start_decl): Do not set DECL_EXTERNAL for initialized
declarations until after calling pushdecl.
(grokdeclarator): Set DECL_EXTERNAL for variables based on use of
"extern" and not on whether the declaration is initialized.

testsuite:
* gcc.dg/pr15360-1.c: New test.

From-SVN: r85156

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

index f4960df..cbaf1fe 100644 (file)
@@ -1,3 +1,11 @@
+2004-07-25  Joseph S. Myers  <jsm@polyomino.org.uk>
+
+       PR c/15360
+       * c-decl.c (start_decl): Do not set DECL_EXTERNAL for initialized
+       declarations until after calling pushdecl.
+       (grokdeclarator): Set DECL_EXTERNAL for variables based on use of
+       "extern" and not on whether the declaration is initialized.
+
 2004-07-25  Daniel Jacobowitz  <dan@debian.org>
 
        * config.gcc (i[34567]86-*-solaris2*, sparc64-*-solaris2*)
index e5e1ee2..f7075b1 100644 (file)
@@ -2766,7 +2766,6 @@ start_decl (tree declarator, tree declspecs, int initialized, tree attributes)
 
   if (initialized)
     {
-      DECL_EXTERNAL (decl) = 0;
       if (current_scope == file_scope)
        TREE_STATIC (decl) = 1;
 
@@ -2833,6 +2832,9 @@ start_decl (tree declarator, tree declspecs, int initialized, tree attributes)
      TEM may equal DECL or it may be a previous decl of the same name.  */
   tem = pushdecl (decl);
 
+  if (initialized)
+    DECL_EXTERNAL (tem) = 0;
+
   return tem;
 }
 
@@ -4599,7 +4601,10 @@ grokdeclarator (tree declarator, tree declspecs,
        if (inlinep)
          pedwarn ("%Jvariable '%D' declared `inline'", decl, decl);
 
-       DECL_EXTERNAL (decl) = extern_ref;
+       /* At file scope, an initialized extern declaration may follow
+          a static declaration.  In that case, DECL_EXTERNAL will be
+          reset later in start_decl.  */
+       DECL_EXTERNAL (decl) = !!(specbits & (1 << (int) RID_EXTERN));
 
        /* At file scope, the presence of a `static' or `register' storage
           class specifier, or the absence of all storage class specifiers
index fca22b7..2d51e4a 100644 (file)
@@ -1,3 +1,8 @@
+2004-07-25  Joseph S. Myers  <jsm@polyomino.org.uk>
+
+       PR c/15360
+       * gcc.dg/pr15360-1.c: New test.
+
 2004-07-25  Daniel Jacobowitz  <dan@debian.org>
 
        * gcc.dg/pragma-align-2.c: New test.
diff --git a/gcc/testsuite/gcc.dg/pr15360-1.c b/gcc/testsuite/gcc.dg/pr15360-1.c
new file mode 100644 (file)
index 0000000..6abb250
--- /dev/null
@@ -0,0 +1,24 @@
+/* Static declarations followed by extern are OK even if the extern
+   declaration is initialized.  Bug 15360 from hozelda at
+   yahoo.com.  */
+/* Origin: Joseph Myers <jsm@polyomino.org.uk> */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+static int a;
+static int a;
+extern int a;
+static int a;
+
+static int b;
+extern int b = 1; /* { dg-warning "initialized and declared" "extern init warning" } */
+static int b;
+static int b;
+
+static int c; /* { dg-error "previous declaration" "" } */
+int c; /* { dg-error "non-static" "correct error" } */
+
+static int d; /* { dg-error "previous declaration" "" } */
+int d = 1; /* { dg-error "non-static" "correct error" } */
+
+void foo (void) { extern int e = 1; } /* { dg-error "has both" "extern init in function" } */