]> granicus.if.org Git - clang/commitdiff
Tighten up the conditions under which we build an implicit function
authorDouglas Gregor <dgregor@apple.com>
Tue, 7 Jul 2009 17:00:05 +0000 (17:00 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 7 Jul 2009 17:00:05 +0000 (17:00 +0000)
declaration for a builtin.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@74917 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
test/Sema/implicit-builtin-redecl.c

index a1ab68ac2a899363f820fd1672d280f04f502224..85210f049d25ecf73ce36fc806e5d5cf0b7d6570 100644 (file)
@@ -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());
index cd99b54553189f524dc5833c0174a054550e2f26..36513bafb0507c1902efe3843a72ad90a5a2a385 100644 (file)
@@ -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