aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/Sema/SemaDecl.cpp9
-rw-r--r--test/Sema/implicit-builtin-redecl.c12
2 files changed, 18 insertions, 3 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index a1ab68ac2a..85210f049d 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -1431,15 +1431,18 @@ Sema::HandleDeclarator(Scope *S, Declarator &D,
if (D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_typedef)
/* Do nothing*/;
else if (R->isFunctionType()) {
- if (CurContext->isFunctionOrMethod())
+ if (CurContext->isFunctionOrMethod() ||
+ D.getDeclSpec().getStorageClassSpec() != DeclSpec::SCS_static)
NameKind = LookupRedeclarationWithLinkage;
} else if (D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_extern)
NameKind = LookupRedeclarationWithLinkage;
+ else if (CurContext->getLookupContext()->isTranslationUnit() &&
+ D.getDeclSpec().getStorageClassSpec() != DeclSpec::SCS_static)
+ NameKind = LookupRedeclarationWithLinkage;
DC = CurContext;
PrevDecl = LookupName(S, Name, NameKind, true,
- D.getDeclSpec().getStorageClassSpec() !=
- DeclSpec::SCS_static,
+ NameKind == LookupRedeclarationWithLinkage,
D.getIdentifierLoc());
} else { // Something like "int foo::x;"
DC = computeDeclContext(D.getCXXScopeSpec());
diff --git a/test/Sema/implicit-builtin-redecl.c b/test/Sema/implicit-builtin-redecl.c
index cd99b54553..36513bafb0 100644
--- a/test/Sema/implicit-builtin-redecl.c
+++ b/test/Sema/implicit-builtin-redecl.c
@@ -12,3 +12,15 @@ void *calloc(int, int, int); // expected-warning{{incompatible redeclaration of
void f1(void) {
calloc(0, 0, 0);
}
+
+void f2() {
+ int index = 1;
+}
+
+static int index;
+
+int f3() {
+ return index << 2;
+}
+
+typedef int rindex; \ No newline at end of file