Add return type checking for overriding virtual functions. We currently don't check covariance but that's next.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@71759 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp
index 726080b..bdd3cc2 100644
--- a/lib/Sema/SemaDeclCXX.cpp
+++ b/lib/Sema/SemaDeclCXX.cpp
@@ -2688,3 +2688,25 @@
SearchForReturnInStmt(*this, Handler);
}
}
+
+bool Sema::CheckOverridingFunctionReturnType(const CXXMethodDecl *New,
+ const CXXMethodDecl *Old) {
+ QualType NewTy = New->getType()->getAsFunctionType()->getResultType();
+ QualType OldTy = Old->getType()->getAsFunctionType()->getResultType();
+
+ QualType CNewTy = Context.getCanonicalType(NewTy);
+ QualType COldTy = Context.getCanonicalType(OldTy);
+
+ if (CNewTy == COldTy &&
+ CNewTy.getCVRQualifiers() == COldTy.getCVRQualifiers())
+ return false;
+
+ // FIXME: Check covariance.
+
+ Diag(New->getLocation(),
+ diag::err_different_return_type_for_overriding_virtual_function)
+ << New->getDeclName() << NewTy << OldTy;
+ Diag(Old->getLocation(), diag::note_overridden_virtual_function);
+
+ return true;
+}