]> granicus.if.org Git - clang/commitdiff
Patch toward synthesizing copy constructors.
authorFariborz Jahanian <fjahanian@apple.com>
Thu, 6 Aug 2009 23:38:16 +0000 (23:38 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Thu, 6 Aug 2009 23:38:16 +0000 (23:38 +0000)
Work in progress.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@78355 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CodeGenFunction.cpp
lib/CodeGen/CodeGenModule.cpp

index 22c099f8dcd26f924834aa32618cf7a39e3421bd..0f155ec648b138349bb776250b7976e52ee0097c 100644 (file)
@@ -240,13 +240,22 @@ void CodeGenFunction::GenerateCode(const FunctionDecl *FD,
   }
   else 
     if (const CXXConstructorDecl *CD = dyn_cast<CXXConstructorDecl>(FD)) {
-      assert(
-             !cast<CXXRecordDecl>(CD->getDeclContext())->
-              hasUserDeclaredConstructor() &&
-             "bogus constructor is being synthesize");
-      StartFunction(FD, FD->getResultType(), Fn, Args, SourceLocation());
-      EmitCtorPrologue(CD);
-      FinishFunction();
+      const CXXRecordDecl *ClassDecl = 
+        cast<CXXRecordDecl>(CD->getDeclContext());
+      (void) ClassDecl;
+      if (CD->isCopyConstructor(getContext())) {
+        assert(!ClassDecl->hasUserDeclaredCopyConstructor() &&
+               "bogus constructor is being synthesize");
+        StartFunction(FD, FD->getResultType(), Fn, Args, SourceLocation());
+        FinishFunction();
+      }
+      else {
+        assert(!ClassDecl->hasUserDeclaredConstructor() &&
+               "bogus constructor is being synthesize");
+        StartFunction(FD, FD->getResultType(), Fn, Args, SourceLocation());
+        EmitCtorPrologue(CD);
+        FinishFunction();
+      }
     }
     
   // Destroy the 'this' declaration.
index 249764e9d99659d267d2ec8303ea36064b3f3f85..8e53651c8e68a7e74eeeb29c21813e213f69f752 100644 (file)
@@ -645,7 +645,11 @@ llvm::Constant *CodeGenModule::GetOrCreateLLVMFunction(const char *MangledName,
     else if (const CXXConstructorDecl *CD = dyn_cast<CXXConstructorDecl>(FD)) {
       const CXXRecordDecl *ClassDecl = 
         cast<CXXRecordDecl>(CD->getDeclContext());
-      if (!ClassDecl->hasUserDeclaredConstructor())
+      if (CD->isCopyConstructor(getContext())) {
+        if (!ClassDecl->hasUserDeclaredCopyConstructor())
+          DeferredDeclsToEmit.push_back(D);
+      }
+      else if (!ClassDecl->hasUserDeclaredConstructor())
         DeferredDeclsToEmit.push_back(D);
     }
   }