]> granicus.if.org Git - clang/commitdiff
Teach FunctionDecl::setPure() to (indirectly) mark the Abstract bit in
authorDouglas Gregor <dgregor@apple.com>
Tue, 28 Sep 2010 21:55:22 +0000 (21:55 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 28 Sep 2010 21:55:22 +0000 (21:55 +0000)
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

include/clang/AST/Decl.h
include/clang/AST/DeclCXX.h
lib/AST/Decl.cpp
lib/AST/DeclCXX.cpp
lib/Sema/SemaDeclCXX.cpp

index 1b1b1df7c67841285b6a07c488faa8dfb700598c..3e1f4bae2d09933949cdd3b4d2c7b713086960c8 100644 (file)
@@ -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,
index 786393cc3132174fcf44c34395450211e56835a8..cdc6d8cf92b663de9d246e70de85826ad9b0dc64 100644 (file)
@@ -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,
index 2f3c006867197bf7b28684e6646b793c2ef5513d..081e5ee6ad4a429aba937c3bd627146c1a4d7cf3 100644 (file)
@@ -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 &&
index 7cdffb7b44ec270d1a7fd8f7262a07f74f3f8e73..036292b6a56751b629729018822d151199237deb 100644 (file)
@@ -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;
index 63acb095a663b9a9380d42d07fb4abbdebe4be0d..425389a6b4bc83a159d488ba12e0e76b27346005 100644 (file)
@@ -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;
   }