Improve function decl merging, patch by Oliver Hunt!
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44253 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Sema/SemaDecl.cpp b/Sema/SemaDecl.cpp
index 2c3b335..30505d6 100644
--- a/Sema/SemaDecl.cpp
+++ b/Sema/SemaDecl.cpp
@@ -238,16 +238,23 @@
return New;
}
- // This is not right, but it's a start. If 'Old' is a function prototype with
- // the same type as 'New', silently allow this. FIXME: We should link up decl
- // objects here.
- if (Old->getBody() == 0 &&
- Old->getCanonicalType() == New->getCanonicalType()) {
- return New;
+ QualType OldQType = Old->getCanonicalType();
+ QualType NewQType = New->getCanonicalType();
+
+ // This is not right, but it's a start.
+ // If Old is a function prototype with no defined arguments we only compare
+ // the return type; If arguments are defined on the prototype we validate the
+ // entire function type.
+ // FIXME: We should link up decl objects here.
+ if (Old->getBody() == 0) {
+ if (OldQType.getTypePtr()->getTypeClass() == Type::FunctionNoProto &&
+ Old->getResultType() == New->getResultType())
+ return New;
+ if (OldQType == NewQType)
+ return New;
}
- if (New->getBody() == 0 &&
- Old->getCanonicalType() == New->getCanonicalType()) {
+ if (New->getBody() == 0 && OldQType == NewQType) {
return 0;
}