diff options
author | Mark Mitchell <mark@codesourcery.com> | 2003-04-15 01:37:03 +0000 |
---|---|---|
committer | Mark Mitchell <mmitchel@gcc.gnu.org> | 2003-04-15 01:37:03 +0000 |
commit | f4e929877c7e155de2f729c3330353762ce1b0ed (patch) | |
tree | 4c8438b79290bd778e2a8b4953783090eea99c1a /gcc | |
parent | e62370313892135cb00868a78d506d915dcc27cc (diff) | |
download | gcc-f4e929877c7e155de2f729c3330353762ce1b0ed.zip gcc-f4e929877c7e155de2f729c3330353762ce1b0ed.tar.gz gcc-f4e929877c7e155de2f729c3330353762ce1b0ed.tar.bz2 |
c-decl.c (grokdeclarator): Reject extern redeclarations of static variables.
* c-decl.c (grokdeclarator): Reject extern redeclarations of
static variables.
* gcc.c-torture/execute/scope-2.c: Move to ...
* gcc.dg/noncompile/scope.c: .... here.
From-SVN: r65615
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/c-decl.c | 17 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/noncompile/scope.c (renamed from gcc/testsuite/gcc.c-torture/execute/scope-2.c) | 2 |
4 files changed, 27 insertions, 2 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 1b40e3a..0aa770c 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2003-04-14 Mark Mitchell <mark@codesourcery.com> + + * c-decl.c (grokdeclarator): Reject extern redeclarations of + static variables. + 2003-04-14 Janis Johnson <janis287@us.ibm.com> * config/rs6000/rs6000.md (define_constants): Define constants for diff --git a/gcc/c-decl.c b/gcc/c-decl.c index be6ff79..50b7219 100644 --- a/gcc/c-decl.c +++ b/gcc/c-decl.c @@ -4375,7 +4375,22 @@ grokdeclarator (declarator, declspecs, decl_context, initialized) } else if (type_quals) type = c_build_qualified_type (type, type_quals); - + + /* It is invalid to create an `extern' declaration for a + variable if there is a global declaration that is + `static'. */ + if (extern_ref && current_binding_level != global_binding_level) + { + tree global_decl; + + global_decl = identifier_global_value (declarator); + if (global_decl + && TREE_CODE (global_decl) == VAR_DECL + && !TREE_PUBLIC (global_decl)) + error ("variable previously declared `static' redeclared " + "`extern'"); + } + decl = build_decl (VAR_DECL, declarator, type); if (size_varies) C_DECL_VARIABLE_SIZE (decl) = 1; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 1fc22ee..ab306f1 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2003-04-14 Mark Mitchell <mark@codesourcery.com> + + * gcc.c-torture/execute/scope-2.c: Move to ... + * gcc.dg/noncompile/scope.c: .... here. + 2003-04-14 Roger Sayle <roger@eyesopen.com> * gcc.dg/20030414-2.c: New test case. diff --git a/gcc/testsuite/gcc.c-torture/execute/scope-2.c b/gcc/testsuite/gcc.dg/noncompile/scope.c index c9a4775..0bfc3f2 100644 --- a/gcc/testsuite/gcc.c-torture/execute/scope-2.c +++ b/gcc/testsuite/gcc.dg/noncompile/scope.c @@ -4,7 +4,7 @@ f () { int v = 4; { - extern int v; + extern int v; /* { dg-error "static" } */ if (v != 3) abort (); } |