diff options
author | John McCall <rjmccall@apple.com> | 2013-04-13 00:20:21 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2013-04-13 00:20:21 +0000 |
commit | 927b0af2f0834bad37e3d2a1953804b0845d8711 (patch) | |
tree | efcad78c36474cbb5b3ec7fd841f029dc0f20d19 | |
parent | dd9bd3ba42ecc3c91ba36f194b993a99371ab825 (diff) |
Don't replace an existing decl in the scope chains with its
local-extern redeclaration; type refinements, default arguments,
etc. must all be locally scoped.
rdar://13535367
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@179430 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 28 | ||||
-rw-r--r-- | test/Sema/extern-redecl.c | 9 | ||||
-rw-r--r-- | test/Sema/function-redecl.c | 4 | ||||
-rw-r--r-- | test/Sema/var-redecl.c | 4 |
4 files changed, 13 insertions, 32 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 6dfc86f501..a2c3c2e147 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -4328,34 +4328,6 @@ Sema::RegisterLocallyScopedExternCDecl(NamedDecl *ND, "Decl is not a locally-scoped decl!"); // Note that we have a locally-scoped external with this name. LocallyScopedExternCDecls[ND->getDeclName()] = ND; - - if (!Previous.isSingleResult()) - return; - - NamedDecl *PrevDecl = Previous.getFoundDecl(); - - // If there was a previous declaration of this entity, it may be in - // our identifier chain. Update the identifier chain with the new - // declaration. - if (S && IdResolver.ReplaceDecl(PrevDecl, ND)) { - // The previous declaration was found on the identifer resolver - // chain, so remove it from its scope. - - if (S->isDeclScope(PrevDecl)) { - // Special case for redeclarations in the SAME scope. - // Because this declaration is going to be added to the identifier chain - // later, we should temporarily take it OFF the chain. - IdResolver.RemoveDecl(ND); - - } else { - // Find the scope for the original declaration. - while (S && !S->isDeclScope(PrevDecl)) - S = S->getParent(); - } - - if (S) - S->RemoveDecl(PrevDecl); - } } llvm::DenseMap<DeclarationName, NamedDecl *>::iterator diff --git a/test/Sema/extern-redecl.c b/test/Sema/extern-redecl.c index 9a085de0c0..64885a08d3 100644 --- a/test/Sema/extern-redecl.c +++ b/test/Sema/extern-redecl.c @@ -33,3 +33,12 @@ void test3declarer() { extern int test3_array[]; int x = sizeof(test3_array); // expected-error {{invalid application of 'sizeof' to an incomplete type 'int []'}} } + +void test4() { + extern int test4_array[]; + { + extern int test4_array[100]; + int x = sizeof(test4_array); // fine + } + int x = sizeof(test4_array); // expected-error {{invalid application of 'sizeof' to an incomplete type 'int []'}} +} diff --git a/test/Sema/function-redecl.c b/test/Sema/function-redecl.c index 3ee8763a56..561f7fae6b 100644 --- a/test/Sema/function-redecl.c +++ b/test/Sema/function-redecl.c @@ -62,7 +62,7 @@ void test2() { // <rdar://problem/6127293> int outer1(int); // expected-note{{previous declaration is here}} struct outer3 { }; -int outer4(int); +int outer4(int); // expected-note{{previous declaration is here}} int outer5; // expected-note{{previous definition is here}} int *outer7(int); @@ -70,7 +70,7 @@ void outer_test() { int outer1(float); // expected-error{{conflicting types for 'outer1'}} int outer2(int); // expected-note{{previous declaration is here}} int outer3(int); // expected-note{{previous declaration is here}} - int outer4(int); // expected-note{{previous declaration is here}} + int outer4(int); int outer5(int); // expected-error{{redefinition of 'outer5' as different kind of symbol}} int* outer6(int); // expected-note{{previous declaration is here}} int *outer7(int); diff --git a/test/Sema/var-redecl.c b/test/Sema/var-redecl.c index f7576b6c02..363458b201 100644 --- a/test/Sema/var-redecl.c +++ b/test/Sema/var-redecl.c @@ -4,7 +4,7 @@ int outer1; // expected-note{{previous definition is here}} extern int outer2; // expected-note{{previous definition is here}} int outer4; int outer4; // expected-note{{previous definition is here}} -int outer5; +int outer5; // expected-note{{previous definition is here}} int outer6(float); // expected-note{{previous definition is here}} int outer7(float); @@ -13,7 +13,7 @@ void outer_test() { extern float outer2; // expected-error{{redefinition of 'outer2' with a different type}} extern float outer3; // expected-note{{previous definition is here}} double outer4; - extern int outer5; // expected-note{{previous definition is here}} + extern int outer5; extern int outer6; // expected-error{{redefinition of 'outer6' as different kind of symbol}} int outer7; extern int outer8; // expected-note{{previous definition is here}} |