]> granicus.if.org Git - clang/commitdiff
Actually generate code for the simple constructors we know we can generate code for.
authorAnders Carlsson <andersca@mac.com>
Wed, 15 Apr 2009 21:02:13 +0000 (21:02 +0000)
committerAnders Carlsson <andersca@mac.com>
Wed, 15 Apr 2009 21:02:13 +0000 (21:02 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69222 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGCXX.cpp

index 7ef147f5f2d07a6e1352ef4657cd4bdcf251f25e..2e48ebec001e5566776b7af3d432d8f06e4c8649 100644 (file)
@@ -149,8 +149,29 @@ void CodeGenModule::EmitCXXConstructor(const CXXConstructorDecl *D,
   SetLLVMFunctionAttributesForDefinition(D, Fn);
 }
 
+static bool canGenerateCXXConstructor(const CXXConstructorDecl *D, 
+                                      ASTContext &Context) {
+  const CXXRecordDecl *RD = D->getParent();
+  
+  // The class has base classes - we don't support that right now.
+  if (RD->getNumBases() > 0)
+    return false;
+  
+  for (CXXRecordDecl::field_iterator I = RD->field_begin(Context), 
+       E = RD->field_end(Context); I != E; ++I) {
+    // We don't support ctors for fields that aren't POD.
+    if (!I->getType()->isPODType())
+      return false;
+  }
+  
+  return true;
+}
+
 void CodeGenModule::EmitCXXConstructors(const CXXConstructorDecl *D) {
-  ErrorUnsupported(D, "C++ constructor", true);
+  if (!canGenerateCXXConstructor(D, getContext())) {
+    ErrorUnsupported(D, "C++ constructor", true);
+    return;
+  }
 
   EmitCXXConstructor(D, Ctor_Complete);
   EmitCXXConstructor(D, Ctor_Base);