[cfe-commits] [PATCH] Smarter implicit copy-construction/copy-assignment.

John McCall rjmccall at apple.com
Mon Feb 11 11:52:40 PST 2013


On Feb 8, 2013, at 12:21 AM, Lang Hames <lhames at gmail.com> wrote:
> Thanks very much for all the help guys. I've attached an updated patch incorporating your feedback. It also fixes a bug -  I had been memcpying members with defaulted but non-trivial assignment operators.

+    // Get source argument for copy constructor. Returns null if not a copy
+    // constructor. 
+    static const VarDecl* getCCSrc(const CXXConstructorDecl *CD,
+                                   FunctionArgList &Args) {
+      if (CD->isCopyOrMoveConstructor() && CD->isImplicitlyDefined())
+        return Args[Args.size() - 1];
+      return 0; 
+    }
+

Please name this something like getTrivialCopySource and use /// comments.

 void CodeGenFunction::EmitCtorPrologue(const CXXConstructorDecl *CD,
@@ -770,8 +1107,15 @@
 
   InitializeVTablePointers(ClassDecl);
 
-  for (unsigned I = 0, E = MemberInitializers.size(); I != E; ++I)
-    EmitMemberInitializer(*this, ClassDecl, MemberInitializers[I], CD, Args);
+  if (getLangOpts().getGC() == LangOptions::NonGC) {
+    ConstructorMemcpyizer CM(*this, CD, Args);
+    for (unsigned I = 0, E = MemberInitializers.size(); I != E; ++I)
+      CM.addMemberInitializer(MemberInitializers[I]);
+    CM.finish();
+  } else {
+    for (unsigned I = 0, E = MemberInitializers.size(); I != E; ++I)
+      EmitMemberInitializer(*this, ClassDecl, MemberInitializers[I], CD, Args);                                                                                                                                                                                                                                                                            
+  }

You shouldn't need to split out specifically on GC mode here, since you're
already setting MemcpyableCtor based on that.

With those changes, go ahead and commit.

John.



More information about the cfe-commits mailing list