aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-11-06 06:07:26 +0000
committerChris Lattner <sabre@nondot.org>2007-11-06 06:07:26 +0000
commite3995fe63cc01668bebed82339479fbc1140768c (patch)
tree3e96d081a23edf53bd5bf9a90e6a577a4344b4c4
parentfcc2d26e73192634dd05fb1b6800b5a063432feb (diff)
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
-rw-r--r--Sema/SemaDecl.cpp5
-rw-r--r--test/Sema/merge-decls.c8
2 files changed, 13 insertions, 0 deletions
diff --git a/Sema/SemaDecl.cpp b/Sema/SemaDecl.cpp
index 40414b46cd..7eec3b0093 100644
--- a/Sema/SemaDecl.cpp
+++ b/Sema/SemaDecl.cpp
@@ -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
index 0000000000..f9a89988f2
--- /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'}}