]> granicus.if.org Git - clang/commitdiff
Fix Sema::ActOnDeclarator() to call MergeFunctionDecl for function decls that aren...
authorSteve Naroff <snaroff@apple.com>
Wed, 9 Jan 2008 23:34:55 +0000 (23:34 +0000)
committerSteve Naroff <snaroff@apple.com>
Wed, 9 Jan 2008 23:34:55 +0000 (23:34 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@45789 91177308-0d34-0410-b5e6-96231b3b80d8

Sema/SemaDecl.cpp
test/Sema/predefined-function.c

index 7d5fc33161d1d0f831d717f9cd432ecaa66c66e4..5e2526e45154dc014c2789fbcb9de8a09e3d3a67 100644 (file)
@@ -637,9 +637,6 @@ Sema::ActOnDeclarator(Scope *S, Declarator &D, DeclTy *lastDecl) {
   // See if this is a redefinition of a variable in the same scope.
   ScopedDecl *PrevDecl = LookupScopedDecl(II, Decl::IDNS_Ordinary,
                                           D.getIdentifierLoc(), S);
-  if (PrevDecl && !S->isDeclScope(PrevDecl))
-    PrevDecl = 0;   // If in outer scope, it isn't the same thing.
-
   ScopedDecl *New;
   bool InvalidDecl = false;
   
@@ -653,8 +650,9 @@ Sema::ActOnDeclarator(Scope *S, Declarator &D, DeclTy *lastDecl) {
     // Handle attributes prior to checking for duplicates in MergeVarDecl
     HandleDeclAttributes(NewTD, D.getDeclSpec().getAttributes(),
                          D.getAttributes());
-    // Merge the decl with the existing one if appropriate.
-    if (PrevDecl) {
+    // Merge the decl with the existing one if appropriate. If the decl is
+    // in an outer scope, it isn't the same thing.
+    if (PrevDecl && S->isDeclScope(PrevDecl)) {
       NewTD = MergeTypeDefDecl(NewTD, PrevDecl);
       if (NewTD == 0) return 0;
     }
@@ -692,7 +690,8 @@ Sema::ActOnDeclarator(Scope *S, Declarator &D, DeclTy *lastDecl) {
     // Transfer ownership of DeclSpec attributes to FunctionDecl
     D.getDeclSpec().clearAttributes();
     
-    // Merge the decl with the existing one if appropriate.
+    // Merge the decl with the existing one if appropriate. Since C functions
+    // are in a flat namespace, make sure we consider decls in outer scopes.
     if (PrevDecl) {
       NewFD = MergeFunctionDecl(NewFD, PrevDecl);
       if (NewFD == 0) return 0;
@@ -731,8 +730,9 @@ Sema::ActOnDeclarator(Scope *S, Declarator &D, DeclTy *lastDecl) {
     HandleDeclAttributes(NewVD, D.getDeclSpec().getAttributes(),
                          D.getAttributes());
      
-    // Merge the decl with the existing one if appropriate.
-    if (PrevDecl) {
+    // Merge the decl with the existing one if appropriate. If the decl is
+    // in an outer scope, it isn't the same thing.
+    if (PrevDecl && S->isDeclScope(PrevDecl)) {
       NewVD = MergeVarDecl(NewVD, PrevDecl);
       if (NewVD == 0) return 0;
     }
index 80b5ab0c6bcafba0f4bce8bed75e05b3abcc470e..d554b8faa890c90b0396411169478c4ea8c6db9e 100644 (file)
@@ -4,9 +4,14 @@ char *funk(int format);
 enum Test {A=-1};
 char *funk(enum Test x);
 
+int eli(float b); // expected-error {{previous definition is here}}
+int b(int c) {return 1;}
+
 int foo();
 int foo()
 {
+    int eli(int (int)); // expected-error {{redefinition of 'eli'}}
+    eli(b);
        return 0;       
 }