forked from OSchip/llvm-project
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:
parent
cd1c055528
commit
95d880933b
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
Loading…
Reference in New Issue