Fix for PR7410. Allow functions in a derived class that improperly overwrite a virtual function in the base class to be inserted into the derived class function list to prevent extra errors every time the derived class is used.

llvm-svn: 134251
This commit is contained in:
Richard Trieu 2011-07-01 20:02:53 +00:00
parent cd1c055528
commit 95d880933b
2 changed files with 14 additions and 1 deletions

View File

@ -4096,10 +4096,10 @@ bool Sema::AddOverriddenMethods(CXXRecordDecl *DC, CXXMethodDecl *MD) {
for (CXXBasePaths::decl_iterator I = Paths.found_decls_begin(),
E = Paths.found_decls_end(); I != E; ++I) {
if (CXXMethodDecl *OldMD = dyn_cast<CXXMethodDecl>(*I)) {
MD->addOverriddenMethod(OldMD->getCanonicalDecl());
if (!CheckOverridingFunctionReturnType(MD, OldMD) &&
!CheckOverridingFunctionExceptionSpec(MD, OldMD) &&
!CheckIfOverriddenFunctionIsMarkedFinal(MD, OldMD)) {
MD->addOverriddenMethod(OldMD->getCanonicalDecl());
AddedAny = true;
}
}

View File

@ -0,0 +1,13 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s
struct BaseReturn {};
struct Base {
virtual BaseReturn Foo() = 0; // expected-note{{overridden virtual function is here}}
};
struct X {};
struct Derived : Base {
X Foo(); // expected-error{{virtual function 'Foo' has a different return type ('X') than the function it overrides (which has return type 'BaseReturn')}}
};
Derived d;