+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*)
if (initialized)
{
- DECL_EXTERNAL (decl) = 0;
if (current_scope == file_scope)
TREE_STATIC (decl) = 1;
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;
}
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
+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.
--- /dev/null
+/* 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" } */