Commit bbbcb2e1 by Joseph Myers Committed by Joseph Myers

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
parent 07a43492
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> 2004-07-25 Daniel Jacobowitz <dan@debian.org>
* config.gcc (i[34567]86-*-solaris2*, sparc64-*-solaris2*) * config.gcc (i[34567]86-*-solaris2*, sparc64-*-solaris2*)
......
...@@ -2766,7 +2766,6 @@ start_decl (tree declarator, tree declspecs, int initialized, tree attributes) ...@@ -2766,7 +2766,6 @@ start_decl (tree declarator, tree declspecs, int initialized, tree attributes)
if (initialized) if (initialized)
{ {
DECL_EXTERNAL (decl) = 0;
if (current_scope == file_scope) if (current_scope == file_scope)
TREE_STATIC (decl) = 1; TREE_STATIC (decl) = 1;
...@@ -2833,6 +2832,9 @@ start_decl (tree declarator, tree declspecs, int initialized, tree attributes) ...@@ -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 may equal DECL or it may be a previous decl of the same name. */
tem = pushdecl (decl); tem = pushdecl (decl);
if (initialized)
DECL_EXTERNAL (tem) = 0;
return tem; return tem;
} }
...@@ -4599,7 +4601,10 @@ grokdeclarator (tree declarator, tree declspecs, ...@@ -4599,7 +4601,10 @@ grokdeclarator (tree declarator, tree declspecs,
if (inlinep) if (inlinep)
pedwarn ("%Jvariable '%D' declared `inline'", decl, decl); 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 /* At file scope, the presence of a `static' or `register' storage
class specifier, or the absence of all storage class specifiers 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> 2004-07-25 Daniel Jacobowitz <dan@debian.org>
* gcc.dg/pragma-align-2.c: New test. * gcc.dg/pragma-align-2.c: New test.
......
/* 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" } */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment