]> granicus.if.org Git - clang/commitdiff
When defining implicit copy constructors, use SetBaseOrMemberInitializers to initiali...
authorAnders Carlsson <andersca@mac.com>
Sat, 1 May 2010 16:39:01 +0000 (16:39 +0000)
committerAnders Carlsson <andersca@mac.com>
Sat, 1 May 2010 16:39:01 +0000 (16:39 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102842 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGClass.cpp
lib/Sema/SemaDeclCXX.cpp

index 56d0e695c58bf8b98e298acc2d24ab9b4b8892ea..966a93c65202da4d9bbf7bd4aeb5f422b6f85f40 100644 (file)
@@ -692,18 +692,6 @@ CodeGenFunction::SynthesizeCXXCopyConstructor(const FunctionArgList &Args) {
   llvm::Value *SrcPtr =
     Builder.CreateLoad(GetAddrOfLocalVar(Args[SrcArgIndex].first));
 
-  for (CXXRecordDecl::base_class_const_iterator Base = ClassDecl->bases_begin();
-       Base != ClassDecl->bases_end(); ++Base) {
-    // FIXME. copy constrution of virtual base NYI
-    if (Base->isVirtual())
-      continue;
-
-    CXXRecordDecl *BaseClassDecl
-      = cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl());
-    EmitClassMemberwiseCopy(ThisPtr, SrcPtr, ClassDecl, BaseClassDecl,
-                            Base->getType());
-  }
-
   for (CXXRecordDecl::field_iterator I = ClassDecl->field_begin(),
        E = ClassDecl->field_end(); I != E; ++I) {
     const FieldDecl *Field = *I;
index 2057b9aa0d22e24ede4b84f89381434e36eca306..6f79a51c84d06d5b17f5227a57fa6638181ea18c 100644 (file)
@@ -1503,7 +1503,10 @@ BuildImplicitBaseInitializer(Sema &SemaRef, CXXConstructorDecl *Constructor,
                           SourceLocation(), ParamType, 0);
     
     // Cast to the base class to avoid ambiguities.
-    SemaRef.ImpCastExprToType(CopyCtorArg, BaseSpec->getType(), 
+    QualType ArgTy = 
+      SemaRef.Context.getQualifiedType(BaseSpec->getType().getUnqualifiedType(), 
+                                       ParamType.getQualifiers());
+    SemaRef.ImpCastExprToType(CopyCtorArg, ArgTy, 
                               CastExpr::CK_UncheckedDerivedToBase,
                               /*isLvalue=*/true, 
                               CXXBaseSpecifierArray(BaseSpec));
@@ -1545,6 +1548,11 @@ BuildImplicitMemberInitializer(Sema &SemaRef, CXXConstructorDecl *Constructor,
                                FieldDecl *Field,
                                CXXBaseOrMemberInitializer *&CXXMemberInit) {
   if (ImplicitInitKind == IIK_Copy) {
+    // FIXME: We should not return early here, but will do so until 
+    // we know how to handle copy initialization of arrays.
+    CXXMemberInit = 0;
+    return false;
+    
     ParmVarDecl *Param = Constructor->getParamDecl(0);
     QualType ParamType = Param->getType().getNonReferenceType();
     
@@ -4212,25 +4220,16 @@ void Sema::DefineImplicitCopyConstructor(SourceLocation CurrentLocation,
 
   ImplicitlyDefinedFunctionScope Scope(*this, CopyConstructor);
 
-  // C++ [class.copy] p209
-  // Before the implicitly-declared copy constructor for a class is
-  // implicitly defined, all the implicitly-declared copy constructors
-  // for its base class and its non-static data members shall have been
-  // implicitly defined.
-  for (CXXRecordDecl::base_class_iterator Base = ClassDecl->bases_begin();
-       Base != ClassDecl->bases_end(); ++Base) {
-    CXXRecordDecl *BaseClassDecl
-      = cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl());
-    if (CXXConstructorDecl *BaseCopyCtor =
-        BaseClassDecl->getCopyConstructor(Context, TypeQuals)) {
-      CheckDirectMemberAccess(Base->getSourceRange().getBegin(),
-                              BaseCopyCtor,
-                              PDiag(diag::err_access_copy_base)
-                                << Base->getType());
-
-      MarkDeclarationReferenced(CurrentLocation, BaseCopyCtor);
-    }
+  if (SetBaseOrMemberInitializers(CopyConstructor, 0, 0, /*AnyErrors=*/false)) {
+    Diag(CurrentLocation, diag::note_member_synthesized_at) 
+    << CXXCopyConstructor << Context.getTagDeclType(ClassDecl);
+    CopyConstructor->setInvalidDecl();
+  } else {
+    CopyConstructor->setUsed();
   }
+
+  // FIXME: Once SetBaseOrMemberInitializers can handle copy initialization of
+  // fields, this code below should be removed.
   for (CXXRecordDecl::field_iterator Field = ClassDecl->field_begin(),
                                   FieldEnd = ClassDecl->field_end();
        Field != FieldEnd; ++Field) {
@@ -4251,7 +4250,6 @@ void Sema::DefineImplicitCopyConstructor(SourceLocation CurrentLocation,
       }
     }
   }
-  CopyConstructor->setUsed();
 }
 
 Sema::OwningExprResult