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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@134251 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Richard Trieu 2011-07-01 20:02:53 +00:00
Родитель c89edf5aaa
Коммит 304e233921
2 изменённых файлов: 14 добавлений и 1 удалений

Просмотреть файл

@ -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;
}
}

13
test/SemaCXX/PR7410.cpp Normal 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;