From 95d880933b940078a5e80cd50a3d206ac528faa7 Mon Sep 17 00:00:00 2001 From: Richard Trieu Date: Fri, 1 Jul 2011 20:02:53 +0000 Subject: [PATCH] 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 --- clang/lib/Sema/SemaDecl.cpp | 2 +- clang/test/SemaCXX/PR7410.cpp | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 clang/test/SemaCXX/PR7410.cpp diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index ad1a62eb7fc0..184c728a026f 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -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(*I)) { + MD->addOverriddenMethod(OldMD->getCanonicalDecl()); if (!CheckOverridingFunctionReturnType(MD, OldMD) && !CheckOverridingFunctionExceptionSpec(MD, OldMD) && !CheckIfOverriddenFunctionIsMarkedFinal(MD, OldMD)) { - MD->addOverriddenMethod(OldMD->getCanonicalDecl()); AddedAny = true; } } diff --git a/clang/test/SemaCXX/PR7410.cpp b/clang/test/SemaCXX/PR7410.cpp new file mode 100644 index 000000000000..6d2cda90b1d3 --- /dev/null +++ b/clang/test/SemaCXX/PR7410.cpp @@ -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;