improve decl merging logic to be more correct with
functions.  Patch contributed by Nuno Lopes, thanks!


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43757 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Sema/SemaDecl.cpp b/Sema/SemaDecl.cpp
index 40414b4..7eec3b0 100644
--- a/Sema/SemaDecl.cpp
+++ b/Sema/SemaDecl.cpp
@@ -245,6 +245,11 @@
       Old->getCanonicalType() == New->getCanonicalType()) {
     return New;
   }
+
+  if (New->getBody() == 0 && 
+      Old->getCanonicalType() == New->getCanonicalType()) {
+    return 0;
+  }
   
   // TODO: CHECK FOR CONFLICTS, multiple decls with same name in one scope.
   // TODO: This is totally simplistic.  It should handle merging functions
diff --git a/test/Sema/merge-decls.c b/test/Sema/merge-decls.c
new file mode 100644
index 0000000..f9a8998
--- /dev/null
+++ b/test/Sema/merge-decls.c
@@ -0,0 +1,8 @@
+// RUN: clang %s -verify -fsyntax-only
+
+void foo(void);
+void foo(void) {} // expected-error{{previous definition is here}}
+void foo(void);
+void foo(void);
+
+void foo(int); // expected-error {{redefinition of 'foo'}}