diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index ebfb9810d660..5c1de6aeb880 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -1456,7 +1456,8 @@ void Sema::MergeVarDecl(VarDecl *New, LookupResult &Previous) { } if (New->hasExternalStorage() && - Old->getLinkage() == InternalLinkage) + Old->getLinkage() == InternalLinkage && + New->getDeclContext() == Old->getDeclContext()) New->setStorageClass(Old->getStorageClass()); // Keep a chain of previous declarations. diff --git a/clang/test/Sema/extern-redecl.c b/clang/test/Sema/extern-redecl.c new file mode 100644 index 000000000000..067e3c21e4c4 --- /dev/null +++ b/clang/test/Sema/extern-redecl.c @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -fsyntax-only %s + +// rdar: // 8125274 +static int a16[]; // expected-warning {{tentative array definition assumed to have one element}} + +void f16(void) { + extern int a16[]; +} +