]> granicus.if.org Git - clang/commitdiff
Fixed a problem where the ASTImporter mishandled in-class initializers.
authorSean Callanan <scallanan@apple.com>
Thu, 3 Mar 2016 01:21:28 +0000 (01:21 +0000)
committerSean Callanan <scallanan@apple.com>
Thu, 3 Mar 2016 01:21:28 +0000 (01:21 +0000)
Previously, the ASTImporter, when copying a FieldDecl, would make the
new FieldDecl use the exact same in-class initializer as the original
FieldDecl, which is a problem since the initializer is in the wrong AST.
The initializer must be imported, just like all the other parts of the
field.

Doug Gregor reviewed this fix.

<rdar://problem/24943405>

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

lib/AST/ASTImporter.cpp

index d6b9424fb4da970a6da64751f8fe203d0404c02e..a21a7e56fcf414b0f62411068c661bde7fb0cab4 100644 (file)
@@ -3038,8 +3038,13 @@ Decl *ASTNodeImporter::VisitFieldDecl(FieldDecl *D) {
                                          D->getInClassInitStyle());
   ToField->setAccess(D->getAccess());
   ToField->setLexicalDeclContext(LexicalDC);
-  if (ToField->hasInClassInitializer())
-    ToField->setInClassInitializer(D->getInClassInitializer());
+  if (Expr *FromInitializer = ToField->getInClassInitializer()) {
+    Expr *ToInitializer = Importer.Import(FromInitializer);
+    if (ToInitializer)
+      ToField->setInClassInitializer(ToInitializer);
+    else
+      return nullptr;
+  }
   ToField->setImplicit(D->isImplicit());
   Importer.Imported(D, ToField);
   LexicalDC->addDeclInternal(ToField);