diff options
author | Douglas Gregor <dgregor@apple.com> | 2010-09-28 21:55:22 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2010-09-28 21:55:22 +0000 |
commit | 2138664dd2cff39de52ff11ca35f653c20b2e4b0 (patch) | |
tree | 4b84b172996daa11a88ded32cb30fa2f73addd70 | |
parent | 4949927fd5f8632ecb1ecdfdac0d13f8357b1984 (diff) |
Teach FunctionDecl::setPure() to (indirectly) mark the Abstract bit in
CXXRecordDecl::DefinitionData, rather than having Sema mark the bit.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@114993 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/AST/Decl.h | 2 | ||||
-rw-r--r-- | include/clang/AST/DeclCXX.h | 3 | ||||
-rw-r--r-- | lib/AST/Decl.cpp | 7 | ||||
-rw-r--r-- | lib/AST/DeclCXX.cpp | 9 | ||||
-rw-r--r-- | lib/Sema/SemaDeclCXX.cpp | 3 |
5 files changed, 18 insertions, 6 deletions
diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h index 1b1b1df7c6..3e1f4bae2d 100644 --- a/include/clang/AST/Decl.h +++ b/include/clang/AST/Decl.h @@ -1280,7 +1280,7 @@ public: /// Whether this virtual function is pure, i.e. makes the containing class /// abstract. bool isPure() const { return IsPure; } - void setPure(bool P = true) { IsPure = P; } + void setPure(bool P = true); /// Whether this function is "trivial" in some specialized C++ senses. /// Can only be true for default constructors, copy constructors, diff --git a/include/clang/AST/DeclCXX.h b/include/clang/AST/DeclCXX.h index 786393cc31..cdc6d8cf92 100644 --- a/include/clang/AST/DeclCXX.h +++ b/include/clang/AST/DeclCXX.h @@ -412,6 +412,9 @@ class CXXRecordDecl : public RecordDecl { /// members have been added. It will be invoked by DeclContext::addDecl() /// whenever a member is added to this record. void addedMember(Decl *D); + + void markedVirtualFunctionPure(); + friend void FunctionDecl::setPure(bool); protected: CXXRecordDecl(Kind K, TagKind TK, DeclContext *DC, diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index 2f3c006867..081e5ee6ad 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -966,6 +966,13 @@ void FunctionDecl::setBody(Stmt *B) { EndRangeLoc = B->getLocEnd(); } +void FunctionDecl::setPure(bool P) { + IsPure = P; + if (P) + if (CXXRecordDecl *Parent = dyn_cast<CXXRecordDecl>(getDeclContext())) + Parent->markedVirtualFunctionPure(); +} + bool FunctionDecl::isMain() const { ASTContext &Context = getASTContext(); return !Context.getLangOptions().Freestanding && diff --git a/lib/AST/DeclCXX.cpp b/lib/AST/DeclCXX.cpp index 7cdffb7b44..036292b6a5 100644 --- a/lib/AST/DeclCXX.cpp +++ b/lib/AST/DeclCXX.cpp @@ -319,8 +319,13 @@ CXXMethodDecl *CXXRecordDecl::getCopyAssignmentOperator(bool ArgIsConst) const { return GetBestOverloadCandidateSimple(Found); } -void -CXXRecordDecl::addedMember(Decl *D) { +void CXXRecordDecl::markedVirtualFunctionPure() { + // C++ [class.abstract]p2: + // A class is abstract if it has at least one pure virtual function. + data().Abstract = true; +} + +void CXXRecordDecl::addedMember(Decl *D) { // Ignore friends and invalid declarations. if (D->getFriendObjectKind() || D->isInvalidDecl()) return; diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 63acb095a6..425389a6b4 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -6668,9 +6668,6 @@ bool Sema::CheckOverridingFunctionAttributes(const CXXMethodDecl *New, bool Sema::CheckPureMethod(CXXMethodDecl *Method, SourceRange InitRange) { if (Method->isVirtual() || Method->getParent()->isDependentContext()) { Method->setPure(); - - // A class is abstract if at least one function is pure virtual. - Method->getParent()->setAbstract(true); return false; } |