]> granicus.if.org Git - clang/commitdiff
improve decl merging logic to be more correct with
authorChris Lattner <sabre@nondot.org>
Tue, 6 Nov 2007 06:07:26 +0000 (06:07 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 6 Nov 2007 06:07:26 +0000 (06:07 +0000)
functions.  Patch contributed by Nuno Lopes, thanks!

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

Sema/SemaDecl.cpp
test/Sema/merge-decls.c [new file with mode: 0644]

index 40414b46cdf26a3959d65bbeaf53e5cc6b297cfe..7eec3b0093a307755b4a9ab6339670871a3950e6 100644 (file)
@@ -245,6 +245,11 @@ FunctionDecl *Sema::MergeFunctionDecl(FunctionDecl *New, ScopedDecl *OldD) {
       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 (file)
index 0000000..f9a8998
--- /dev/null
@@ -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'}}