[cfe-commits] r105374 - in /cfe/trunk/lib: AST/CXXInheritance.cpp Sema/SemaDeclCXX.cpp

Anders Carlsson andersca at mac.com
Wed Jun 2 18:00:02 PDT 2010


Author: andersca
Date: Wed Jun  2 20:00:02 2010
New Revision: 105374

URL: http://llvm.org/viewvc/llvm-project?rev=105374&view=rev
Log:
Add all final overriders to the map.

Modified:
    cfe/trunk/lib/AST/CXXInheritance.cpp
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp

Modified: cfe/trunk/lib/AST/CXXInheritance.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/CXXInheritance.cpp?rev=105374&r1=105373&r2=105374&view=diff
==============================================================================
--- cfe/trunk/lib/AST/CXXInheritance.cpp (original)
+++ cfe/trunk/lib/AST/CXXInheritance.cpp Wed Jun  2 20:00:02 2010
@@ -559,22 +559,23 @@
       for (; OverMethods.first != OverMethods.second; ++OverMethods.first) {
         const CXXMethodDecl *CanonOM
           = cast<CXXMethodDecl>((*OverMethods.first)->getCanonicalDecl());
+
+        // C++ [class.virtual]p2:
+        //   A virtual member function C::vf of a class object S is
+        //   a final overrider unless the most derived class (1.8)
+        //   of which S is a base class subobject (if any) declares
+        //   or inherits another member function that overrides vf.
+        //
+        // Treating this object like the most derived class, we
+        // replace any overrides from base classes with this
+        // overriding virtual function.
+        Overriders[CanonOM].replaceAll(
+                               UniqueVirtualMethod(CanonM, SubobjectNumber,
+                                                   InVirtualSubobject));
+
         if (CanonOM->begin_overridden_methods()
-                                       == CanonOM->end_overridden_methods()) {
-          // C++ [class.virtual]p2:
-          //   A virtual member function C::vf of a class object S is
-          //   a final overrider unless the most derived class (1.8)
-          //   of which S is a base class subobject (if any) declares
-          //   or inherits another member function that overrides vf.
-          //
-          // Treating this object like the most derived class, we
-          // replace any overrides from base classes with this
-          // overriding virtual function.
-          Overriders[CanonOM].replaceAll(
-                                 UniqueVirtualMethod(CanonM, SubobjectNumber,
-                                                     InVirtualSubobject));
+                                       == CanonOM->end_overridden_methods())
           continue;
-        } 
 
         // Continue recursion to the methods that this virtual method
         // overrides.
@@ -582,6 +583,12 @@
                                        CanonOM->end_overridden_methods()));
       }
     }
+
+    // C++ [class.virtual]p2:
+    //   For convenience we say that any virtual function overrides itself.
+    Overriders[CanonM].add(SubobjectNumber,
+                           UniqueVirtualMethod(CanonM, SubobjectNumber,
+                                               InVirtualSubobject));
   }
 }
 

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=105374&r1=105373&r2=105374&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Wed Jun  2 20:00:02 2010
@@ -2326,6 +2326,10 @@
   CXXFinalOverriderMap FinalOverriders;
   RD->getFinalOverriders(FinalOverriders);
 
+  // Keep a set of seen pure methods so we won't diagnose the same method
+  // more than once.
+  llvm::SmallPtrSet<const CXXMethodDecl *, 8> SeenPureMethods;
+  
   for (CXXFinalOverriderMap::iterator M = FinalOverriders.begin(), 
                                    MEnd = FinalOverriders.end();
        M != MEnd; 
@@ -2345,6 +2349,9 @@
       if (!SO->second.front().Method->isPure())
         continue;
 
+      if (!SeenPureMethods.insert(SO->second.front().Method))
+        continue;
+
       Diag(SO->second.front().Method->getLocation(), 
            diag::note_pure_virtual_function) 
         << SO->second.front().Method->getDeclName();





More information about the cfe-commits mailing list