diff options
author | Anders Carlsson <andersca@mac.com> | 2010-06-03 01:00:02 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2010-06-03 01:00:02 +0000 |
commit | ffdb2d2a8860c601b35575855494f45d85cf14d9 (patch) | |
tree | 23a0187a91ae7b4cd45370a0bbcc45241cc9d05a /lib | |
parent | cd7c4d8c122e7cfd6ce2a65db9e824bfe17634c2 (diff) |
Add all final overriders to the map.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@105374 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/AST/CXXInheritance.cpp | 35 | ||||
-rw-r--r-- | lib/Sema/SemaDeclCXX.cpp | 7 |
2 files changed, 28 insertions, 14 deletions
diff --git a/lib/AST/CXXInheritance.cpp b/lib/AST/CXXInheritance.cpp index d616e42e00..bdba01402c 100644 --- a/lib/AST/CXXInheritance.cpp +++ b/lib/AST/CXXInheritance.cpp @@ -559,22 +559,23 @@ void FinalOverriderCollector::Collect(const CXXRecordDecl *RD, 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 @@ void FinalOverriderCollector::Collect(const CXXRecordDecl *RD, 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)); } } diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 8630e73cee..76a2f4f612 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -2326,6 +2326,10 @@ bool Sema::RequireNonAbstractType(SourceLocation Loc, QualType T, 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 @@ bool Sema::RequireNonAbstractType(SourceLocation Loc, QualType T, 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(); |