diff options
-rw-r--r-- | gcc/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/c-decl.c | 9 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pr15360-1.c | 24 |
4 files changed, 44 insertions, 2 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index f4960df..cbaf1fe 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -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*) diff --git a/gcc/c-decl.c b/gcc/c-decl.c index e5e1ee2..f7075b1 100644 --- a/gcc/c-decl.c +++ b/gcc/c-decl.c @@ -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 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index fca22b7..2d51e4a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -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 index 0000000..6abb250 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr15360-1.c @@ -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" } */ |