From bbbcb2e1c4e122b5e10c3439c271ab0e00adbf08 Mon Sep 17 00:00:00 2001 From: Joseph Myers Date: Sun, 25 Jul 2004 19:42:24 +0100 Subject: [PATCH] re PR c/15360 (c99: extern w/initializer; extern w/internal linkage) 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 | 8 ++++++++ gcc/c-decl.c | 9 +++++++-- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/pr15360-1.c | 24 ++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr15360-1.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index f4960dfe8ee..cbaf1fe5b38 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2004-07-25 Joseph S. Myers + + 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 * config.gcc (i[34567]86-*-solaris2*, sparc64-*-solaris2*) diff --git a/gcc/c-decl.c b/gcc/c-decl.c index e5e1ee242c3..f7075b182ee 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 fca22b74038..2d51e4aed09 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2004-07-25 Joseph S. Myers + + PR c/15360 + * gcc.dg/pr15360-1.c: New test. + 2004-07-25 Daniel Jacobowitz * 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 00000000000..6abb2500671 --- /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 */ +/* { 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" } */ -- 2.30.2