[cfe-commits] r134251 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/SemaCXX/PR7410.cpp

Richard Trieu rtrieu at google.com
Fri Jul 1 13:02:53 PDT 2011


Author: rtrieu
Date: Fri Jul  1 15:02:53 2011
New Revision: 134251

URL: http://llvm.org/viewvc/llvm-project?rev=134251&view=rev
Log:
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.


Added:
    cfe/trunk/test/SemaCXX/PR7410.cpp
Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=134251&r1=134250&r2=134251&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Jul  1 15:02:53 2011
@@ -4096,10 +4096,10 @@
     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;
         }
       }

Added: cfe/trunk/test/SemaCXX/PR7410.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/PR7410.cpp?rev=134251&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/PR7410.cpp (added)
+++ cfe/trunk/test/SemaCXX/PR7410.cpp Fri Jul  1 15:02:53 2011
@@ -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;





More information about the cfe-commits mailing list