Don't swap function decls, and add them to the scope as they are 
encountered.  Mixing up the decls is unintuitive, and confuses the AST 
destruction code. Fixes PR2360.

Note that there is a need to look up the characteristics and 
declarations of a function associated with a particular name or decl, 
but the original swapping code doesn't solve it properly. 
http://lists.cs.uiuc.edu/pipermail/cfe-dev/2008-May/001644.html is one 
suggestion for how to fix that.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@51584 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 8b89045..2856403 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -910,13 +910,7 @@
       NewFD = MergeFunctionDecl(NewFD, PrevDecl, Redeclaration);
       if (NewFD == 0) return 0;
       if (Redeclaration) {
-        // Note that the new declaration is a redeclaration of the
-        // older declaration. Then return the older declaration: the
-        // new one is only kept within the set of previous
-        // declarations for this function.
-        FunctionDecl *OldFD = (FunctionDecl *)PrevDecl;
-        OldFD->AddRedeclaration(NewFD);
-        return OldFD;
+        NewFD->setPreviousDeclaration(cast<FunctionDecl>(PrevDecl));
       }
     }
     New = NewFD;