diff options
author | mmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4> | 2003-04-15 01:37:03 +0000 |
---|---|---|
committer | mmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4> | 2003-04-15 01:37:03 +0000 |
commit | c26210535efc12fa30997a2f42deadb5c871de9e (patch) | |
tree | 4c8438b79290bd778e2a8b4953783090eea99c1a /gcc/c-decl.c | |
parent | d737e66d9252fcd3ff34c5eab1bc8db561bb47d0 (diff) | |
download | gcc-c26210535efc12fa30997a2f42deadb5c871de9e.tar.gz |
* 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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@65615 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/c-decl.c')
-rw-r--r-- | gcc/c-decl.c | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/gcc/c-decl.c b/gcc/c-decl.c index be6ff79059d..50b7219b393 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; |